Defer and stream
Send a response in pieces: @defer delivers slow fields after the rest, @stream sends list items as they are ready, over a multipart HTTP response.
Defer and stream
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A normal response waits for the slowest field. `@defer` on a fragment sends everything else first and the deferred fields later, in the same HTTP response.
- `@stream` on a list field sends the first `initialCount` items immediately and the rest as they become available.
- The first payload has `hasNext: true`; each later payload carries an `incremental` list with a `path` saying where the data belongs, and the last has `hasNext: false`.
- The client must opt in with an `Accept` header for incremental delivery, such as `multipart/mixed`; a client that only accepts JSON gets a 406 from Yoga.
- Defer when a field is slow and not needed for first paint; do not defer fast fields, because each extra payload has a cost.
The problem: one slow field holds the page
A normal GraphQL response is all or nothing. The server runs every resolver, waits for the slowest, and sends one JSON document. If post { id title stats { views } } includes a stats lookup that takes 300 ms, the title waits for it too, though the page could already show the title.
You could fix this by sending two requests. That works, but now you have two operations to keep in sync, two loading states, and the server cannot share work between them. Incremental delivery keeps one operation and splits the response.
@defer
@defer goes on a fragment spread or inline fragment. Fields inside it are resolved but sent later:
{
post {
id
title
... @defer {
stats { views }
}
}
}
I ran this on Yoga 6.1.0 with @graphql-yoga/plugin-defer-stream 4.1.0 and graphql-js 17.1.0. Post.stats sleeps for 300 ms. The response arrived as a multipart HTTP response in two parts:
+0ms {"data":{"post":{"id":"1","title":"Hello"}},"hasNext":true}
+301ms {"incremental":[{"data":{"stats":{"views":42}},"path":["post"]}],"hasNext":false}
The first part has the data that was ready and hasNext: true. The second says where its data goes (path: ["post"]) and hasNext: false. The client merges the second into the first.
The mental model is a restaurant ticket where the kitchen sends out the starter as soon as it is ready instead of holding the table until the dessert is done. All dishes belong to one order, but they land at different times.
@stream
@stream is for list fields. The server sends the first initialCount items and the rest as they resolve:
{ feed @stream(initialCount: 1) { id title } }
Here Query.feed is an async generator that yields a post every 200 ms:
+0ms {"data":{"feed":[{"id":"1","title":"Post 1"}]},"hasNext":true}
+201ms {"incremental":[{"items":[{"id":"2","title":"Post 2"}],"path":["feed",1]}],"hasNext":true}
+403ms {"incremental":[{"items":[{"id":"3","title":"Post 3"}],"path":["feed",2]}],"hasNext":true}
+403ms {"hasNext":false}
The path ends with the list index where the new item goes. The resolver has to be able to produce items over time, so use an async iterator for the field, as in the subscriptions lesson. A resolver that returns a complete array leaves nothing to stream.
Turning it on
Both directives are part of the GraphQL incremental-delivery work, which has been carried in graphql-js 17 releases. On this setup I did not need to declare them in my SDL; with graphql-js 16 you would add directive @defer(...) and directive @stream(...) yourself. Check your server’s docs for current status, because the wire format changed across drafts. The path-based shape above is what Yoga produced in my run; other servers or versions can send a different shape.
On the HTTP side the client must say it can read it. Yoga serves incremental results as multipart/mixed or as an event stream. I repeated the request with Accept: application/json:
status 406
A client that only understands JSON does not get a broken half-response; it gets refused. Client libraries with incremental-delivery support send the header for you.
When to use it
Defer fields that are slow and not needed for the first paint: recommendations, analytics, a view count. Do not defer fast fields. Every extra payload is another chunk to send and parse, so deferring a cheap field makes the page slower, not faster.
A deferred fragment that fails reports its error in a later payload, after the first has been delivered. I made Post.stats throw: the first payload was unchanged, and the second came back as {"incremental":[{"data":null,"path":["post"],"errors":[{"message":"stats down","path":["post","stats"]}]}],"hasNext":false}. Clients must handle errors arriving late, which changes how you think about errors and partial responses.
What the video covers
Jeff Auriemma’s “You should know about @defer in GraphQL” is five minutes from October 2026. The description says large queries need not be slow, and that @defer gets the fastest and highest-urgency data on screen sooner. It covers @defer only; @stream is not in the title or description, so the section above carries that. Michael Staib and Rob Richard’s longer talk introduces both directives and is the better follow-up, but it is from 2022 and predates the newer formats.
Where this fits
You have seen the three delivery shapes GraphQL offers beyond a single response: serial mutations, streamed subscriptions, and incremental responses. The next group turns to the server side of all this: how fields get their values. Next: resolvers.
Check yourself
What problem does `@defer` solve that splitting the page into two queries also solves, and what does it add?
Both let fast data render before slow data. `@defer` does it in one request, so the server can share work across parts and the client keeps one operation, one cache write path and one set of variables.
How does a client know a response is not finished after the first payload?
The payload includes `hasNext: true`. The final payload has `hasNext: false`.
Where does a deferred payload's data attach in the result?
Each `incremental` entry has a `path`, for example `["post"]`, and the client merges its `data` into the result at that path.
When is `@defer` the wrong tool?
When the field is fast, because the extra payload adds overhead for nothing, or when the first screen needs it, since deferring would only delay what the user is waiting for.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.