Consuming GraphQL with rails - ruby-on-rails

Let's say someone has setup a GraphQL endpoint. I want send and consume GraphQL queries from within my Rails application, as opposed to using React and Relay.
Are there examples of this, or known gems or libraries?

You can send an HTTP request to the GraphQL that's structured in the proper query structure as specified by the GraphQL specification: http://graphql.org/docs/queries/

Related

Ruby on Rails equivalent to Django's SchemaGenerator

I am currently looking into adding Swagger to an API that I work on. I found rswag, but from what I can tell, I would have to manually write specs for every endpoint in my API. This API has hundreds of endpoints, so this isn't very feasible.
Django REST Framework has SchemaGenerator which can generate an OpenAPI schema, either as a static file to commit and edit as you see fit or a dynamic endpoint which can be consumed by Swagger UI. Is there any equivalent for Ruby on Rails?
As a side note, I am also using jsonapi-resources. I'd be open to tools that are specific to JSON API.

Where should I put the requests related to excel export/import on Graphql?

I have an architectural doubt.
I am using the GraphQL as an API provider and I need to develop some API requests to import data from excel and to export data to excel on my project.
Where should I create this using the GraphQL API?
I researched and discovered it is possible to create customized queries and mutations on the GraphQL... In this case...
This should be a query?
This should be a mutation?
Or other thing?
Side note: I am using the GraphQL API on my Ruby on Rails project via the graphql-ruby gem and I am also using the mongoid gem to deal with the database.
Comparing to REST API this is how it should be
REST GrapQL
GET GrapQL Query
POST, PUT, PATCH, DELETE GrapQL Mutation
If you are just querying go for GraphQL Query
If you are modifying the data use Mutations
In your case import should be mutation whereas export can be query
Read more - here

Integrating RelayJS and Azure table storage

The documentation on RelayJS says the RelayJS can use node.js as a GraphQL server, but not ASP.NET web service.
How can I use RelayJS with ASP.NET web api end point?
How can I use RelayJS with ASP.NET web api end point?
TL;DR;
By placing a GraphQL server in-between Relay client-side and ASP.NET web api end point.
The Getting Started page of Relay documentation clearly mentions that 2 additional things are needed to use Relay:
A GraphQL Schema: This is your data model. You need to map your ASP.NET web API to a GraphQL schema.
A GraphQL Server: Your client-side speaks to this server. In your case, this GraphQL server will talk to your ASP.NET web API.
A good example of this is GraphQL schema and server wrapping Star Wars API.
Some conecptual clarifications about your question
Relay is a specification. It's actually called GraphQL Relay Specification. It's not restricted to JavaScript. Check Awesome Relay to find the list of languages for which Relay libraries are already available.
It helps to think of Relay and GraphQL as 2 sides:
server-side consisting of GraphQL server, which speaks the schema. It can receive queries and mutation requests. How you prepare and provide the requested data depend on back-end logic. For example, you may have your own database, which you use directly to fetch / prepare the exposed data. Or you may use an external API to fetch / prepare data.
There are libraries in languages other than JavaScript to help you write GraphQL schema and server. Check Awesome GraphQL.
client-side using Relay library, which talks to a GraphQL server and fetches data as needed.

What is a suitable backend for relayjs?

I am having trouble understanding how to hook up a backend that will support relayjs. Does GraphQL/Relay automatically help store queries? I.e. if I implement a REST backend that returns a json blob with everything, will Relay take care of the data query optimizations? I'm not entirely sure of the abstraction between Relay and backend/database.
Take a look at Getting Started in the Relay documentation. Relay requires that you have a GraphQL server that understands GraphQL queries and can respond with valid response payloads.
GraphQL provides an abstraction with which Relay uses to interface with your backend. GraphQL is not a database, but rather a layer that sits on top of your server application code. For example, you could implement a GraphQL server that sits in front of your REST server as demonstrated by the graphql/swapi-graphql repository.
Nick Schrock's presentation of GraphQL at #Scale 2015 also provides a good overview.

Best practice of parsing RESTful WebService response with Rails

I'm developing a JAX-RS application and it's working fine. Now, I want to develop a web service client application using Rails. And my question is which is the best way to parse a RESTful webservice's response in Rails?
It depends on what the service is returning. I'd say that you could use a variety of gems to do it. Lately I've been using HTTParty to get and parse automatically the response of a call to a RESTful API.
Once I get all the data I then map it to a model so that's it's easier to manipulate later on. The way you'll do this mapping will really depend on the type on response you'll get.

Resources