Reputation: 308
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" ?
Upvotes: 2
Views: 1245
Reputation: 4587
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
Upvotes: 0
Reputation: 670
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.
Upvotes: 1