graphql / graphql/graphql-spec

@stream: Can a client know when individual streams complete?

Open
#830 6 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I've been looking into GraphQL for a potential API and as I was reading about the `@stream` RFC, I noticed that this approach of `hasNext: boolean` on the response JSON means that there's is no way for a client to know when an individual stream has completed. Not really sure where to look to see if this has been discussed, but didn't spot anything.

For example with
```
type Query {
faster: [String!]!
slower: [String!]!
}
```
and querying
```
{
faster @stream(initialCount: 0)
slower @stream(initialCount: 0)
}
```
with something like
```
async *faster() {
for (let i = 0; i < 5; i++) {
yield "faster: " + i;
await delay(50);
}
},
async *slower() {
for (let i = 0; i < 5; i++) {
yield "slower: " + i;
await delay(500);
}
},
```
you end up with
```
{"data":{"faster":["faster: 0"],"slower":["slower: 0"]},"hasNext":true}
{"data":"faster: 1","path":["faster",1],"hasNext":true}
{"data":"faster: 2","path":["faster",2],"hasNext":true}
{"data":"faster: 3","path":["faster",3],"hasNext":true}
{"data":"faster: 4","path":["faster",4],"hasNext":true}
{"data":"slower: 1","path":["slower",1],"hasNext":true}
{"data":"slower: 2","path":["slower",2],"hasNext":true}
{"data":"slower: 3","path":["slower",3],"hasNext":true}
{"data":"slower: 4","path":["slower",4],"hasNext":true}
{"hasNext":false}
```

From a client's standpoint, there is no way to know that the 5 items in `faster` are the only items it will receive, so anything working client-side would be stuck waiting for `slower` to finish so that `hasNext: false` could be sent so that it could know that no more `faster` entries coming.

I'd have expected the overall transport-level connection/query state would likely already make it clear when all pending pieces of a query have finished, so shouldn't `hasNext` denote the end of a specific stream instance's data?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.