@@ -10,7 +10,8 @@ the case that any _execution error_ was raised and replaced with {null}.
1010## Response Format
1111
1212:: A GraphQL request returns a _ response_ . A _ response_ is either an _ execution
13- result_ , a _ response stream_ , or a _ request error result_ .
13+ result_ , a _ response stream_ , an _ incremental stream_ , or a _ request error
14+ result_ .
1415
1516### Execution Result
1617
@@ -43,6 +44,14 @@ value of this entry is described in the "Extensions" section.
4344subscription and the request included execution. A response stream must be a
4445stream of _ execution result_ .
4546
47+ ### Incremental Stream
48+
49+ :: A GraphQL request returns an _ incremental stream_ when the GraphQL service
50+ has deferred or streamed data as a result of the ` @defer ` or ` @stream `
51+ directives. When the result of the GraphQL operation is an incremental stream,
52+ the first value will be an _ initial execution result_ , followed by one or more
53+ _ execution update result_ .
54+
4655### Request Error Result
4756
4857:: A GraphQL request returns a _ request error result_ when one or more _ request
@@ -70,6 +79,59 @@ The _request error result_ map must not contain an entry with key {"data"}.
7079The _ request error result_ map may also contain an entry with key ` extensions ` .
7180The value of this entry is described in the "Extensions" section.
7281
82+ ### Initial Execution Result
83+
84+ :: An _ initial execution result_ is the first value yielded by an _ incremental
85+ stream_ .
86+
87+ An _ initial execution result_ must be a map.
88+
89+ The _ initial execution result_ must contain an entry with key {"data"}, and may
90+ contain entries with keys {"errors"} and {"extensions"}. The value of these
91+ entries are defined in the same way as an _ execution result_ as described in the
92+ "Data", "Errors", and "Extensions" sections below.
93+
94+ The _ initial execution result_ must contain an entry with the key {"hasNext"}.
95+ The value of this entry must be {true}.
96+
97+ The _ initial execution result_ may contain an entry with the key {"pending"}.
98+ The value of this entry must be a non-empty list of _ pending result_ . Each
99+ _ pending result_ must be a map as described in the "Pending Result" section
100+ below.
101+
102+ The _ initial execution result_ may contain an entry with they key
103+ {"incremental"}. The value of this entry must be a non-empty list of
104+ _ incremental result_ . Each _ incremental result_ must be a map as described in
105+ the "Incremental Result" section below.
106+
107+ The _ initial execution result_ may contain an entry with they key {"completed"}.
108+ The value of this entry must be a non-empty list of _ completed result_ . Each
109+ _ completed result_ must be a map as described in the "Completed Result" section
110+ below.
111+
112+ ### Execution Update Result
113+
114+ :: An _ execution update result_ is the value yielded by an _ incremental stream_
115+ for all values except the first.
116+
117+ An _ execution update result_ must be a map.
118+
119+ Unlike the _ initial execution result_ , an _ execution update result_ must not
120+ contain entries with keys {"data"} or {"errors"}.
121+
122+ An _ execution update result_ may contain an entry with the key {"extensions"}.
123+ The value of this entry is described in the "Extensions" section.
124+
125+ An _ execution update result_ must contain an entry with the key {"hasNext"}. The
126+ value of this entry must be {true} for all but the last response in the
127+ _ incremental stream_ . The value of this entry must be {false} for the last
128+ response of the incremental stream.
129+
130+ The _ initial execution result_ may contain entries with keys {"pending"},
131+ {"incremental"}, and/or {"completed"}. The value of these entries are defined in
132+ the same way as an _ initial execution result_ as described in the "Pending
133+ Result", "Incremental Result", and "Completed Result" sections below.
134+
73135### Response Position
74136
75137<a name =" sec-Path " >
@@ -94,6 +156,9 @@ represents a path in the response, not in the request.
94156When a _ response path_ is present on an _ error result_ , it identifies the
95157_ response position_ which raised the error.
96158
159+ When a _ response path_ is present on an _ incremental result_ , it identifies the
160+ _ response position_ of the incremental data update.
161+
97162A single field execution may result in multiple response positions. For example,
98163
99164``` graphql example
@@ -323,15 +388,171 @@ discouraged.
323388
324389### Extensions
325390
326- The {"extensions"} entry in an _ execution result_ or _ request error result_ , if
327- set, must have a map as its value. This entry is reserved for implementers to
328- extend the protocol however they see fit, and hence there are no additional
329- restrictions on its contents.
391+ The {"extensions"} entry in an _ execution result_ , _ request error result_ ,
392+ _ initial execution result_ , or a _ execution update result_ , if set, must have a
393+ map as its value. This entry is reserved for implementers to extend the protocol
394+ however they see fit, and hence there are no additional restrictions on its
395+ contents.
396+
397+ ### Pending Result
398+
399+ :: A _ pending result_ is used to communicate to clients that the GraphQL service
400+ has chosen to incrementally deliver data associated with a ` @defer ` or ` @stream `
401+ directive. Each pending result corresponds to a specific ` @defer ` or ` @stream `
402+ directive located at a _ response position_ in the response data. The presence of
403+ a pending result indicates that clients should expect the associated data in
404+ either the current response, or one of the following responses.
405+
406+ ** Pending Result Format**
407+
408+ A _ pending result_ must be a map.
409+
410+ Every _ pending result_ must contain an entry with the key {"id"} with a string
411+ value. This {"id"} should be used by clients to correlate pending results with
412+ _ incremental result_ and _ completed result_ . The {"id"} value must be unique for
413+ the entire _ incremental stream_ response. There must not be any other pending
414+ result in the _ incremental stream_ that contains the same {"id"}.
415+
416+ Every _ pending result_ must contain an entry with the key {"path"}. When the
417+ pending result is associated with a ` @stream ` directive, it indicates the list
418+ at this _ response position_ is not known to be complete. Clients should expect
419+ the GraphQL Service to incrementally deliver the remainder list items of this
420+ list. When the pending result is associated with a ` @defer ` directive, it
421+ indicates that the response fields contained in the deferred fragment are not
422+ known to be complete. Clients should expect the GraphQL Service to incrementally
423+ deliver the remainder of the fields contained in the deferred fragment at this
424+ _ response position_ .
425+
426+ If the associated ` @defer ` or ` @stream ` directive contains a ` label ` argument,
427+ the pending result must contain an entry {"label"} with the value of this
428+ argument. Clients should use this entry to differentiate the _ pending results_
429+ for different deferred fragments at the same _ response position_ .
430+
431+ If a pending result is not returned for a ` @defer ` or ` @stream ` directive,
432+ clients must assume that the GraphQL service chose not to incrementally deliver
433+ this data, and the data can be found either in the {"data"} entry in the
434+ _ initial execution result_ , or one of the prior _ execution update result_ in the
435+ _ incremental stream_ .
436+
437+ :: The _ associated pending result_ is a specific _ pending result_ associated
438+ with any given _ incremental result_ or _ completed result_ . The associated
439+ pending result can be determined by finding the pending result where the value
440+ of its {"id"} entry is the same value of the {"id"} entry of the given
441+ incremental result or completed result. The associated pending result must
442+ appear in the _ incremental stream_ , in the same or prior _ initial execution
443+ result_ or _ execution update result_ as the given incremental result or
444+ completed result.
445+
446+ ### Incremental Result
447+
448+ :: The _ incremental result_ is used to deliver data that the GraphQL service has
449+ chosen to incrementally deliver. An incremental result may be ether an
450+ _ incremental list result_ or an _ incremental object result_ .
451+
452+ An _ incremental result_ must be a map.
453+
454+ Every _ incremental result_ must contain an entry with the key {"id"} with a
455+ string value. The definition of _ associated pending result_ describes how this
456+ value is used to determine the associated pending result for a given
457+ _ incremental result_ .
458+
459+ #### Incremental List Result
460+
461+ :: An _ incremental list result_ is a _ incremental result_ used to deliver
462+ additional list items for a list field with a ` @stream ` directive. The
463+ _ associated pending result_ for this _ incremental list result_ must be
464+ associated with a ` @stream ` directive.
465+
466+ The _ response position_ for an _ incremental list result_ is the {"path"} entry
467+ from its _ associated pending result_ .
468+
469+ ** Incremental List Result Format**
470+
471+ Every _ incremental list result_ must contain an entry with the key {"id"}, used
472+ to determine the _ associated pending result_ for this _ incremental result_ .
473+
474+ Every _ incremental list result_ must contain an {"items"} entry. The {"items"}
475+ entry must contain a list of additional list items for the list field in the
476+ incremental list result's _ response position_ . The value of this entry must be a
477+ list of the same type of the response field at this _ response position_ .
478+
479+ If any _ execution error_ were raised during the execution of the results in
480+ {"items"} and these errors propagate to a _ response position_ higher than the
481+ _ incremental list result_ 's response position, The incremental list result is
482+ considered failed and should not be included in the _ incremental stream_ . The
483+ errors that caused this failure will be included in a _ completed result_ .
484+
485+ If any _ execution error_ were raised during the execution of the results in
486+ {"items"} and these errors did not propagate to a path higher than the
487+ _ incremental list result_ 's path, the incremental list result must contain an
488+ entry with key {"errors"} containing these execution errors. The value of this
489+ entry is described in the "Errors" section.
490+
491+ #### Incremental Object Result
492+
493+ :: An _ incremental object result_ is a _ incremental result_ used to deliver
494+ additional response fields that were contained in one or more fragments with a
495+ ` @defer ` directive. The _ associated pending result_ for this _ incremental object
496+ result_ must be associated with a ` @defer ` directive.
497+
498+ ** Incremental Object Result Format**
499+
500+ The _ incremental object result_ may contain a {"subPath"} entry. If this entry
501+ is present, The incremental object result's _ response position_ can be
502+ determined by concatenating the value of the _ associated pending result_ 's
503+ {"path"} entry with the value of this {"subPath"} entry. If no {"subPath"} entry
504+ is present, the _ response position_ is the value of the associated pending
505+ result's {"path"} entry.
506+
507+ An _ incremental object result_ may be used to deliver data for response fields
508+ that were contained in more than one deferred fragments. In that case, the
509+ _ associated pending result_ of the incremental object result must be a _ pending
510+ result_ with the longest {"path"}.
511+
512+ Every _ incremental object result_ must contain a {"data"} entry. The {"data"}
513+ entry must contain a map of additional response fields. The {"data"} entry in an
514+ incremental object result will be of the type of the field at the incremental
515+ object result's _ response position_ .
516+
517+ If any _ execution error_ were raised during the execution of the results in
518+ {"data"} and these errors propagated to a _ response position_ higher than the
519+ _ incremental object result_ 's response position, The incremental object result
520+ is considered failed and should not be included in the incremental stream. The
521+ errors that caused this failure will be included in a _ completed result_ .
522+
523+ If any _ execution error_ were raised during the execution of the results in
524+ {"data"} and these errors did not propagate to a _ response position_ higher than
525+ the _ incremental object result_ 's response position, the incremental object
526+ result must contain an entry with key {"errors"} containing these execution
527+ errors. The value of this entry is described in the "Errors" section.
528+
529+ ### Completed Result
530+
531+ :: A _ completed result_ is used to communicate that the GraphQL service has
532+ completed the incremental delivery of the data associated with the _ associated
533+ pending result_ . The corresponding data must have been completed in the same
534+ _ initial execution result_ or _ execution update result_ in which this completed
535+ result appears.
536+
537+ ** Completed Result Format**
538+
539+ A _ completed result_ must be a map.
540+
541+ Every _ completed result_ must contain an entry with the key {"id"} with a string
542+ value. The definition of _ associated pending result_ describes how this value is
543+ used to determine the associated pending result for a given _ completed result_ .
544+
545+ A _ completed result_ may contain an {"errors"} entry. When the {"errors"} entry
546+ is present, it informs clients that the delivery of the data from the
547+ _ associated pending result_ has failed, due to an execution error propagating to
548+ a _ response position_ higher than the _ incremental result_ 's response position.
549+ The {"errors"} entry must contain these execution errors. The value of this
550+ entry is described in the "Errors" section.
330551
331552### Additional Entries
332553
333554To ensure future changes to the protocol do not break existing services and
334- clients, the _ execution result _ and _ request error result _ maps must not contain
555+ clients, any of the maps described in the "Response" section must not contain
335556any entries other than those described above. Clients must ignore any entries
336557other than those described above.
337558
0 commit comments