-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: optimize gateway by batching queries #667
feat: optimize gateway by batching queries #667
Conversation
Good work! |
- unit testing
- parallel execution
- fixed messsage
Why a service would not support batched queries? I would enable that by default. |
I agree with you @mcollina and I'll apply this configurable default on the Gateway, as I see it as well as a best practice. Your question made me think though: I think that maybe a service could have batching disabled because it's not aware of being used as a service from a gateway instance. |
How could you disable batching in a service? I think that's part of the GraphQL spec. |
My thought goes to a Service made with Fastify + Mercurius and batched queries disabled:
Do you suggest that batched queries should be enabled by default in Mercurius, regardless if it's about building a service for a gateway? I am a very new contributor to the project, so I might be missing something. |
- updated docs - better testing - setting batched as default
lib/gateway/get-query-result.js
Outdated
|
||
const { preGatewayExecutionHandler } = require('../handlers') | ||
|
||
const mergeQueries = (queries) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add some comments on the code to understand the context/logic
Thanks @giacomorebonato, I know understand this better. When I wrote the issue originally, I thought we would use queries like the following: query user1 {
...
}
query user2 {
...
} Instead, you implemented this using https://mercurius.dev/#/docs/batched-queries - which is a feature I even forgot we supported. As things are, I think you implemented this correctly and it should be enabled on demand and not by default as it is off-standard. Note that there is currently no way to execute multiple queries in parallel in GraphQL by the spec: graphql/graphql-spec#375. Note that batching is currently at rfc stage at: https://github.com/graphql/graphql-over-http/blob/main/rfcs/Batching.md. Could you please set the default to back `false? I'm sorry for the confusion. |
- improved jsdoc - set default batching to false
docs/federation.md
Outdated
{ | ||
name: 'user', | ||
url: 'http://localhost:3000/graphql' // queries will be batched into one request | ||
// same as setting allowBatchedQueries: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please uncomment this
docs/federation.md
Outdated
#### Batched Queries to services | ||
|
||
To fully leverage the DataLoader pattern a Gateway assumes that can send a request with batched queries to its services. | ||
This configuration can be disabled if the service doesn't support batched queries instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not match the implementation anymore.
- updating doc about defaults - link to batched queries doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
#649
To do:
lib/gateway.js
about thistest/gateway/errors-with-batching.js
test/gateway/batching-on-both-gateway-and-services.js