@@ -8,11 +8,11 @@ request.
8
8
A response may contain both a partial response as well as encountered errors in
9
9
the case that a field error occurred on a field which was replaced with {null}.
10
10
11
+ A response to a GraphQL operation must be a map or an event stream of maps. The
12
+ value of this map is described in the "Response Format" section.
11
13
12
14
## Response Format
13
15
14
- A response to a GraphQL operation must be a map.
15
-
16
16
If the operation encountered any errors, the response map must contain an
17
17
entry with key ` errors ` . The value of this entry is described in the "Errors"
18
18
section. If the operation completed without encountering any errors, this entry
@@ -23,11 +23,24 @@ with key `data`. The value of this entry is described in the "Data" section. If
23
23
the operation failed before execution, due to a syntax error, missing
24
24
information, or validation error, this entry must not be present.
25
25
26
+ If the response of the GraphQL operation is an event stream, each response map
27
+ must contain an entry with key ` hasNext ` . The value of this entry is ` true ` for
28
+ all but the last response in the stream. The value of this entry is ` false ` for
29
+ the last response of the stream. This entry is not required for GraphQL
30
+ operations that return a single response map.
31
+
26
32
The response map may also contain an entry with key ` extensions ` . This entry,
27
33
if set, must have a map as its value. This entry is reserved for implementors
28
34
to extend the protocol however they see fit, and hence there are no additional
29
35
restrictions on its contents.
30
36
37
+ When the response of the GraphQL operation is an event stream, the first value
38
+ will be the initial response. All subsequent values must contain ` label ` and
39
+ ` path ` entries. These two entries are used by clients to identify the the
40
+ ` @defer ` or ` @stream ` directive from the GraphQL operation that triggered this
41
+ value to be returned by the event stream. The combination of these two entries
42
+ must be unique across all values returned by the event stream.
43
+
31
44
To ensure future changes to the protocol do not break existing servers and
32
45
clients, the top level response map must not contain any entries other than the
33
46
three described above.
@@ -43,6 +56,11 @@ requested operation. If the operation was a query, this output will be an
43
56
object of the schema's query root type; if the operation was a mutation, this
44
57
output will be an object of the schema's mutation root type.
45
58
59
+ If the result of the operation is an event stream, the ` data ` entry in
60
+ subsequent values will be an object of the type of a particular field in the
61
+ GraphQL result. The adjacent ` path ` field will contain the path segments of
62
+ the field this data is associated with.
63
+
46
64
If an error was encountered before execution begins, the ` data ` entry should
47
65
not be present in the result.
48
66
@@ -82,14 +100,8 @@ associated syntax element.
82
100
If an error can be associated to a particular field in the GraphQL result, it
83
101
must contain an entry with the key ` path ` that details the path of the
84
102
response field which experienced the error. This allows clients to identify
85
- whether a ` null ` result is intentional or caused by a runtime error.
86
-
87
- This field should be a list of path segments starting at the root of the
88
- response and ending with the field associated with the error. Path segments
89
- that represent fields should be strings, and path segments that
90
- represent list indices should be 0-indexed integers. If the error happens
91
- in an aliased field, the path to the error should use the aliased name, since
92
- it represents a path in the response, not in the query.
103
+ whether a ` null ` result is intentional or caused by a runtime error. The value
104
+ of this field is described in the "Path" section.
93
105
94
106
For example, if fetching one of the friends' names fails in the following
95
107
query:
@@ -220,6 +232,29 @@ still discouraged.
220
232
```
221
233
222
234
235
+ ## Path
236
+
237
+ A ` path ` field allows for the association to a particular field in a GraphQL
238
+ result. This field should be a list of path segments starting at the root of the
239
+ response and ending with the field to be associated with. Path segments
240
+ that represent fields should be strings, and path segments that
241
+ represent list indices should be 0-indexed integers. If the path is associated to
242
+ an aliased field, the path should use the aliased name, since it represents a path in the response, not in the query.
243
+
244
+ When the ` path ` field is present on a GraphQL response, it indicates that the
245
+ ` data ` field is not the root query or mutation result, but is rather associated to
246
+ a particular field in the root result.
247
+
248
+ When the ` path ` field is present on an "Error result", it indicates the response field which experienced the error.
249
+
250
+ ## Label
251
+
252
+ If the response of the GraphQL operation is an event stream, subsequent values
253
+ will contain a string field ` label ` . This ` label ` is the same label passed to
254
+ the ` @defer ` or ` @stream ` directive that triggered this value. This allows
255
+ clients to identify which ` @defer ` or ` @stream ` directive is associated with
256
+ this value.
257
+
223
258
## Serialization Format
224
259
225
260
GraphQL does not require a specific serialization format. However, clients
0 commit comments