Skip to content

Commit dbdf5b5

Browse files
robrichardyaacovCR
authored andcommitted
add detailed incremental example
1 parent 9ff6494 commit dbdf5b5

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

spec/Section 7 -- Response.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,86 @@ The `incremental` entry in the response is a non-empty list of Defer or Stream
270270
payloads. If the response of the GraphQL operation is a response stream, this
271271
field may appear on both the initial and subsequent values.
272272

273+
For example, a query containing both defer and stream:
274+
275+
```graphql example
276+
query {
277+
person(id: "cGVvcGxlOjE=") {
278+
...HomeWorldFragment @defer(label: "homeWorldDefer")
279+
name
280+
films @stream(initialCount: 1, label: "filmsStream") {
281+
title
282+
}
283+
}
284+
}
285+
fragment HomeWorldFragment on Person {
286+
homeWorld {
287+
name
288+
}
289+
}
290+
```
291+
292+
The response stream might look like:
293+
294+
Response 1, the initial response does not contain any deferred or streamed
295+
results.
296+
297+
```json example
298+
{
299+
"data": {
300+
"person": {
301+
"name": "Luke Skywalker",
302+
"films": [{ "title": "A New Hope" }]
303+
}
304+
},
305+
"hasNext": true
306+
}
307+
```
308+
309+
Response 2, contains the defer payload and the first stream payload.
310+
311+
```json example
312+
{
313+
"incremental": [
314+
{
315+
"label": "homeWorldDefer",
316+
"path": ["person"],
317+
"data": { "homeWorld": { "name": "Tatooine" } }
318+
},
319+
{
320+
"label": "filmsStream",
321+
"path": ["person", "films", 1],
322+
"items": [{ "title": "The Empire Strikes Back" }]
323+
}
324+
],
325+
"hasNext": true
326+
}
327+
```
328+
329+
Response 3, contains an additional stream payload.
330+
331+
```json example
332+
{
333+
"incremental": [
334+
{
335+
"label": "filmsStream",
336+
"path": ["person", "films", 2],
337+
"items": [{ "title": "Return of the Jedi" }]
338+
}
339+
],
340+
"hasNext": true
341+
}
342+
```
343+
344+
Response 4, contains no incremental payloads, {hasNext} set to {false} indicates
345+
the end of the stream.
346+
347+
```json example
348+
{
349+
"hasNext": false
350+
}
351+
```
352+
273353
#### Stream payload
274354

275355
A stream payload is a map that may appear as an item in the `incremental` entry

0 commit comments

Comments
 (0)