-1

Since GraphQL provides a single API endpoint to do API queries and there could a situation where we have written multiple Graphql queries in our frontend application (which provides data to the different components of our application) and these Graph QL queries should run in parallel.

Does GraphQL combine these queries into one and make a single API request or does it make multiple API requests for multiple queries?

Note: Not using any library yet. Just a random question that came into my mind while going through the docs.

  • Welcome to Stack Overflow. To get the most out of the site it may be better to just try some tutorials out and then post your code or errors here - in order to get assistance. – Michael Nelles Mar 29 '20 at 15:36

1 Answers1

1

GraphQL is a query language and an execution runtime. The specification tells us how a client should write queries and how a server should validate and execute those queries. It's not concerned with how the client gets those queries to the server (i.e. the transport).

You've not indicated what client library, if any, you're using to make your requests. If you're using Apollo Client, by default each operation will result in a separate request to the server. However, you can use apollo-link-batch-http to batch multiple queries into a single request. To my knowledge, Relay offers similar functionality.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183
  • Thank you very much for your clarification. I haven't started implementing it yet. I was just going through the docs and this question came in my mind. Thought to ask here. – Mohd Ilyas Mar 30 '20 at 18:29