Skip to content

Commit c55cef6

Browse files
committed
add payload fields to Response section
1 parent c894ef1 commit c55cef6

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

spec/Section 3 -- Type System.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,12 @@ A GraphQL schema describes directives which are used to annotate various parts
17531753
of a GraphQL document as an indicator that they should be evaluated differently
17541754
by a validator, executor, or client tool such as a code generator.
17551755

1756-
GraphQL implementations should provide the `@skip`, `@include`, `@defer` and `@stream` directives.
1756+
GraphQL implementations should provide the `@skip` and `@include` directives.
1757+
1758+
GraphQL implementations are not required to implement the `@defer` and `@stream`
1759+
directives. If they are implemented, they must be implemented according to the
1760+
specification. GraphQL implementations that do not support these directives must
1761+
not make them available via introspection.
17571762

17581763
GraphQL implementations that support the type system definition language must
17591764
provide the `@deprecated` directive if representing deprecated portions of

spec/Section 6 -- Execution.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ ExecuteQuery(query, schema, variableValues, initialValue):
141141
* For each {payload} in {subsequentPayloads}:
142142
* If {payload} is a Deferred Fragment Record:
143143
* Yield the value from calling {ResolveDeferredFragmentRecord(payload, variableValues, subsequentPayloads)}.
144+
* If {payload} is not the final payload in {subsequentPayloads}
145+
* Add an entry to {payload} named `hasNext` with the value {true}.
146+
* If {payload} is the final payload in {subsequentPayloads}
147+
* Add an entry to {payload} named `hasNext` with the value {false}.
144148
* If {payload} is a Stream Record:
145149
* Yield ResolveStreamRecord(payload, variableValues, subsequentPayloads).
146150

@@ -712,7 +716,7 @@ Note: It is common for {resolver} to be asynchronous due to relying on reading
712716
an underlying database or networked service to produce a value. This
713717
necessitates the rest of a GraphQL executor to handle an asynchronous
714718
execution flow. In addition, a commom implementation of {generator} is to leverage
715-
asynchronos iterators or asynchronos generators provided by many programing languages.
719+
asynchronous iterators or asynchronous generators provided by many programing languages.
716720

717721
### Value Completion
718722

spec/Section 7 -- Response.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ request.
88
A response may contain both a partial response as well as encountered errors in
99
the case that a field error occurred on a field which was replaced with {null}.
1010

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.
1113

1214
## Response Format
1315

14-
A response to a GraphQL operation must be a map.
15-
1616
If the operation encountered any errors, the response map must contain an
1717
entry with key `errors`. The value of this entry is described in the "Errors"
1818
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
2323
the operation failed before execution, due to a syntax error, missing
2424
information, or validation error, this entry must not be present.
2525

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+
2632
The response map may also contain an entry with key `extensions`. This entry,
2733
if set, must have a map as its value. This entry is reserved for implementors
2834
to extend the protocol however they see fit, and hence there are no additional
2935
restrictions on its contents.
3036

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+
3144
To ensure future changes to the protocol do not break existing servers and
3245
clients, the top level response map must not contain any entries other than the
3346
three described above.
@@ -43,6 +56,11 @@ requested operation. If the operation was a query, this output will be an
4356
object of the schema's query root type; if the operation was a mutation, this
4457
output will be an object of the schema's mutation root type.
4558

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+
4664
If an error was encountered before execution begins, the `data` entry should
4765
not be present in the result.
4866

@@ -82,14 +100,8 @@ associated syntax element.
82100
If an error can be associated to a particular field in the GraphQL result, it
83101
must contain an entry with the key `path` that details the path of the
84102
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.
93105

94106
For example, if fetching one of the friends' names fails in the following
95107
query:
@@ -220,6 +232,29 @@ still discouraged.
220232
```
221233

222234

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+
223258
## Serialization Format
224259

225260
GraphQL does not require a specific serialization format. However, clients

0 commit comments

Comments
 (0)