-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Transport-level query batching #531
Conversation
This is great. We should do some things before merging and shipping the feature:
|
Shortly, When Relay provides a list of queries for fetching. I can pass it back in any order, but should know for which query which payload addressed. So I combine all queries with id into an array, then send them to the server. Server proceeds all queries and passes array payloads with its ids back. Client gets the response, traversing by the array and maps by Example of batch request: [
{
"id": "q0",
"query": `
query ViewerQueries {
viewer {
...F0
}
}
fragment F0 on Viewer {
id,
usersCount
}
`,
"variables": {}
},
{
"id": "q1",
"query": "query ViewerQueries { ... }",
"variables": {}
}
] Batch response: {
"id":"q0",
"payload":{
"data": {
"viewer": {
"id": "Q2FiaW5ldDo1N2FjOWE2NDVhZTUxYTI1ZmYxZGNkMzg=",
"usersCount": 0,
}
}
}
},
{
"id":"q1",
"payload": {
"data": null,
"errors": [ ... ]
}
}
] |
OK, so the idea is that Relay batching is built with the idea that requests might arrive out of order or separately, even if they were sent as a batch? This seems like it would never come up with HTTP batching, right? So maybe we could remove the |
@stubailo if graphql/express-graphql#100 will be accepted, then I'll remove But if I realize network layer via WebSockets, then I'll return |
I'm not sure if batching is necessary at all over a WebSocket transport since the concept of a "HTTP roundtrip" no longer exists. |
Nice catch. @Poincare totally agreed with you. |
Ooops. Not agree again. Suppose the following scenario: We have 4 queries from relay PS. |
export function createNetworkInterface( | ||
uri: string, | ||
opts: RequestInit = {}, | ||
transportBatching = false |
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 don't think just having this as a third argument is a good idea. I'd replace uri
with NetworkInterfaceOptions
or something.
So you can do createNetworkInterface('/graphql')
or createNetworkInterface({ uri: '/graphql', serverBatching: 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.
Should opts
be a part of NetworkInterfaceOptions
or should it be a second argument? For example, would you do:
createNetworkInterface({
uri: '/graphql',
opts: { ... },
serverBatching: true,
})
or
createNetworkInterface({
uri: '/graphql',
serverBatching: true,
},
{ ... })
The first option makes more sense to me but it probably breaks existing code that uses createNetworkInterface
.
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.
We can do the first one in a backwards-compatible way by checking if the first argument is a string
. then for 1.0 we can remove the backcompat?
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.
Sounds good to me.
return addQueryMerging(new HTTPFetchNetworkInterface(uri, opts)) as HTTPNetworkInterface; | ||
const { | ||
transportBatching = false, | ||
opts = {}, |
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.
Can we change this to a more descriptive name since before it was only internal? Like fetchOptions
.
This PR works (tested on GitHunt), but if we merge the typescript compiler options PR first, it will require a few changes so it is waiting for that. |
…alt with TypeScript bugs
a967123
to
4418faa
Compare
Adds transport-level query batching support to Apollo Client (see #505).
TODO: