GraphQl Request Parameters to Sql - graphql

Is there a way to build a SQL query from GraphQL parameters? Currently, we are using 'https://www.npmjs.com/package/graphql-parse-resolve-info' to get the requested fields and building queries.
However, there may be a library that can help you with this. Our tech stack is: Nestjs, GraphQL, Sequelize

Related

Apollo Graphql - Default values on network error?

I am working with Apollo's Graphql React Client.
I would like to have some "default values" that queries return when they fail to fetch the data, for example, when offline.
I know that I can check if an error occured and populate it manually, but this means that I will have to do it and sync the data between each component that uses the useQuery hook with intersecting results.
I was unable to find anything, but is there some way/best practice to do it?
Thank you

Fetching data into graphql

I am trying to execute very basic query into graphql but getting following error. any input or suggestion.

Can we have GraphQL response in XML

I am trying to add a GraphQL wrapper on an existing project's REST APIs.
I need to define queries for every existing API. However, a few of them are returning XML responses.
As per my findings, GraphQL's response is always a valid JSON (Link)
Is it possible in any way to return the XML response from the GraphQL query?

Is there any tool to debug the rest calls made by GraphQL Playground?

I'm not able to figure out why the REST API call works just fine in Postman but not in the GraphQL Playground. If I could see the actual REST call being made by GraphQL, would be helpful to debug the issue.
Firecamp's GraphQL client lets you test the GraphQL as an API call or as a Query way.
Here is the dedicated GraphQL client
Here is REST like GraphQL client
Note: Make sure that you double-check the method and headers while using REST-like GraphQL client. IN most cases method would be post and header should contains Content-Type: application-json / application/graphql
The GraphQL playground allows to send GraphQL queries/mutations to your GraphQL server. You can see the requests that are send using the network tab of a browser dev tools.
For example, if a server is in running at the following address http://localhost:4000/graphql, sending a query/mutation, a XHR request will be sent to it. In the Request Payload of the Headers section there is the query/mutation itself.
In the Response section you can see the returned response.
You can start having a look at the returned response of your query/mutation. Perhaps there is something wrong in the related resolve function in GraphQL.

How to cascade GraphQL?

I'm currently using "client side GraphQL server" to wrap RESTful endpoint to GraphQL endpoint.
But what if server side is also a GraphQL endpoint? How can I queue another GraphQL server in a GraphQL server by a lightweight way?
Or more generally, If I have GraphQL servers "A" and "B", providing microservices, then I use a GraphQL server "C" to integrate "A" and "B". Should I use some kind of "Server side Client" using apollo-client or so to queue "A" and "B" in "C" ?
I've never seen client side GraphQL used that way, but I imagine it would work like usual. You have your query with a resolver which returns data. In this case, you would use a GraphQL request instead of a REST api request, but the principle is the same.
Remember, GraphQL is not that different from any other api. You send HTTP requests (with GraphQL, all of the requests are POST) to a URL endpoint (with GraphQL, the URL is always the same) and send parameter data with your request (with GraphQL, this is where the entire query goes).
I imagine you could translate your variables from the client GraphQL query to the variables in the server GraphQL query and construct your query that way.
With cURL, you can query with a format like this:
$ curl -XPOST -H "Content-Type:application/graphql" -d 'query RootQueryType { count }' http://localhost:3000/graphql
And the response would look like this:
{
"data": {
"count": 0
}
}
Just use the request library you are using on the client to hit the REST client, but modify it to match the API of the GraphQL server you are trying to reach.
Actually, I think it's the job of resolving function to interact with your micro services. For more information, you should have a look at GraphQL and Microservice Architecture

Resources