feat(core): Implement GraphQL SSE Response Support #3050
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This implements support for
text/event-stream
responses, as per GraphQL SSE.We've used GraphQL Yoga's "push" mechanism as a general template for what this must look like: https://github.com/dotansimha/graphql-yoga/blob/d2060c1/packages/graphql-yoga/src/plugins/resultProcessor/push.ts
And this generally adheres to the GraphQL SSE protocol: https://github.com/enisdenjo/graphql-sse/blob/master/PROTOCOL.md
The current implementation found it unnecessary to respect
event:
type fields, instead it will just loosely look atdata:
fields and attempt to parse them.We generally regard this as an alternative to
multipart/mixed
responses, and the protocol is loosely supported alongside it, while basically being an alternative totext/event-stream
.Currently, it's unclear to us when which one would be preferred, and we believe that's up to implementors and APIs to decide.
We also know that subscription operations could now be implemented with either response formats, however, we haven't decided yet how the default
fetchExchange
could switch over to handlesubscription
operations. This could be an option on theClient
, but, we think that overall we already have a lot offetch
-related options on theClient
, some of which may have to go. Discussion needed ✌️5.9kB -> 5.98 kB
min+gzipSet of changes
parseEventStream
handler alongsideparseMultipartMixed