Serve
Features
Performance/Cache
Defer & Stream

Defer and Stream

💡

This page is currently under construction and expected to change. Please feel free to reach out to us directly in case you are having any troubles.

Stream and defer are directives that allow you to improve latency for clients by sending the most important data as soon as it’s ready.

As applications grow, the GraphQL operation documents can get bigger. The server will only send the response back once all the data requested in the query is ready. However, not all requested data is of equal importance, and the client may not need all of the data at once. To remedy this, GraphQL specification working group is working on introducing new @defer and @stream directives which allows applications to request a subset of data which is critical and get the rest of the data in subsequent responses from the server. This proposal is in Stage 2, meaning GraphQL libraries can start implementing this as experimental feature to provide feedback to the working group.

💡

Stream and Defer are experimental features and not yet stable. The implementation can and will change. Furthermore, there is no yet a stable specification for the incremental delivery protocol.

Installation

Enabling support for the @defer and @stream directive requires installing a plugin.

npm i @graphql-yoga/plugin-defer-stream
mesh.config.ts
import { useDeferStream } from '@graphql-yoga/plugin-defer-stream'
 
export const serveConfig = {
  plugins: pluginCtx => [useDeferStream()]
}

See more