One of the disadvantages of GraphQL’s request/response model is that the GraphQL response is not returned to clients until the entire request has finished processing. However, not all requested data may be of equal importance, and in some use cases it may be possible for applications to act on a subset of the requested data. An application can speed up its time-to-interactive if the GraphQL server can send the most important data as soon as it’s ready. The new @defer and @stream directives allow GraphQL servers to do exactly that by returning multiple payloads from a single GraphQL response.
Similar to @defer the @stream directive also allows the client to receive data before the entire result is ready. @stream can be used on list fields. Whereas @defer can be used on used on fragment spreads and inline fragments.
One of the disadvantages of GraphQL’s request/response model is that the GraphQL response is not returned to clients until the entire request has finished processing. However, not all requested data may be of equal importance, and in some use cases it may be possible for applications to act on a subset of the requested data. An application can speed up its time-to-interactive if the GraphQL server can send the most important data as soon as it’s ready. The new
@defer
and@stream
directives allow GraphQL servers to do exactly that by returning multiple payloads from a single GraphQL response.Similar to
@defer
the@stream
directive also allows the client to receive data before the entire result is ready.@stream
can be used on list fields. Whereas@defer
can be used on used on fragment spreads and inline fragments.References
https://graphql.org/blog/2020-12-08-improving-latency-with-defer-and-stream-directives/