-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
@stream and @defer: Giving the server control of incremental delivery #693
Comments
A use case I am trying to solve where this would help is integration LLMs into GraphQL which work by streaming tokens (a chunk of characters) as an async streamed response. This is more driven by the server than the client. It feels like the server should have the power to dictate if a field needs to be streamed in some use cases |
I think it's critical that the client opts-in to streamed responses, however I think the schema should definitely be able to indicate which fields should be streamed, such that tools like GraphiQL will automatically add the |
@Keweiqu indeed; the client can ask for any list field to be streamed via the client-to-server @stream directive. What I’m suggesting is that the schema could indicate which fields would benefit from being streamed. Maybe the server knows that streaming |
@benjie I see your point. I was thinking in general any composite type list would have latency benefits from streaming since resolving subfields are also delayed. Even if resolving the list itself doesn't have any latency difference, subfields would make a difference, and also parsing a smaller payload on the client side? |
@Keweiqu Indeed, that could certainly add up in some circumstances. I may not have worded my previous comment very well, what I'm actually proposing is that some fields (such as LLM token streams or other lists that are produced in a slow item-by-item basis) should almost always be streamed, and we should give a way for schema authors to indicate this as a hint to their clients so that when they auto-complete the field in GraphiQL or their IDE it maybe comes with the |
@benjie schema hints for defer/stream is a very interesting suggestion. |
@stream and @defer are collaborative efforts between the client and server to improve the application’s time-to-interact metric. This issue discusses some important reasons to enable the server to choose whether to deliver data asynchronously.
Eagerly fulfill @defer and @stream
In the case that a piece of less important data happens to be expensive, @defer and @stream enables the application to improve the TTI without making the expensive data slower. However, these two criteria are not always aligned.
If the deferred data are cheap and fast to retrieve & if the important (non-deferred) data is the bottleneck: the server may decide to include this data in the initial payload as the data is already ready. In this situation unnecessarily delaying delivery can negatively affect the user experience by triggering multiple renders.
(Caveats: although eagerly fulfill @defer and @stream may be considered “free” from the server side, there is a client side cost of processing more data for the initial payload in terms of JSON deserialize. There are potential optimizations through braces matching that seeks to the deferred data and skip the entire subtree.)
Fast Experimentation and Iteration
Often times, it is hard to tell the true cost of a piece of data upfront:
Therefore, when using @defer and @stream it’s useful to set up an experiment and compare the result. If a client has a long release cycle, turning @defer and @stream on and off on the server side is much faster.
Additional benefits of server side configuration:
Proposed standardization:
For the list reasons above, it is essential to allow server side control of whether to respect @defer and @stream. Therefore, we’d like to propose to specify the requirement in the spec that:
The text was updated successfully, but these errors were encountered: