Reputation: 21
Is it ideal or bad practice to separate query?
For example, should I query page. Or split this master query and query customer and footer?
Is there a performance difference difference between hitting one vs muliple queries like this?
query page {
customer {
Name
Gender
age
}
footer {
supportUrl
}
}
Vs
query customer {
Name
Gender
Age
}
Query footer {
SupportUrl
}
Upvotes: 0
Views: 583
Reputation: 158995
Running a single query will usually be faster; how much faster depends much more on the external network conditions than anything in your code.
Running a single query will result in a single network round trip. If your code would otherwise run the two queries serially in separate HTTP requests, having to wait for one network round trip to complete before starting the second could be observably slower, depending on the network between the server and the end user.
The only real downside to running the two queries together is if you had some queries that were quite slow, and ran the fast and slow ones together; then you wouldn't get responses to the fast queries until everything had completed.
The server is allowed to execute the queries in parallel. If your client code can run the queries in parallel as well, you can mitigate the visible performance penalty from having multiple separate queries, and this would address the problem of having specific queries that ran slowly on the server side.
Upvotes: 0