Skip to content

Commit d127655

Browse files
robrichardbenjie
andcommitted
Editorial: Define _response map_
This creates a definition for Response Map, defined as the map normally returned by graphql queries and mutations containing data and/or errors. The definition of Response is updated to include both Response Map, and Response Stream (for subscriptions). For Incremental Delivery I plan on updating Response to also include _Incremental Stream_. Address feedback Update spec/Section 7 -- Response.md Co-authored-by: Benjie <[email protected]>
1 parent d3762d2 commit d127655

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

spec/Section 6 -- Execution.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
301301

302302
- Let {responseStream} be a new _event stream_.
303303
- When {sourceStream} emits {sourceValue}:
304-
- Let {response} be the result of running
304+
- Let {responseMap} be the result of running
305305
{ExecuteSubscriptionEvent(subscription, schema, variableValues,
306306
sourceValue)}.
307307
- If internal {error} was raised:
308308
- Cancel {sourceStream}.
309309
- Complete {responseStream} with {error}.
310-
- Otherwise emit {response} on {responseStream}.
310+
- Otherwise emit {responseMap} on {responseStream}.
311311
- When {sourceStream} completes normally:
312312
- Complete {responseStream} normally.
313313
- When {sourceStream} completes with {error}:
@@ -804,22 +804,22 @@ A _field error_ is an error raised from a particular field during value
804804
resolution or coercion. While these errors should be reported in the response,
805805
they are "handled" by producing a partial response.
806806

807-
Note: This is distinct from a _request error_ which results in a response with
808-
no data.
807+
Note: This is distinct from a _request error_ which results in a _response map_
808+
with no {"data"}.
809809

810810
If a field error is raised while resolving a field, it is handled as though the
811811
field returned {null}, and the error must be added to the {"errors"} list in the
812-
response.
812+
_response map_.
813813

814814
If the result of resolving a field is {null} (either because the function to
815815
resolve the field returned {null} or because a field error was raised), and that
816816
field is of a `Non-Null` type, then a field error is raised. The error must be
817-
added to the {"errors"} list in the response.
817+
added to the {"errors"} list in the _response map_.
818818

819819
If the field returns {null} because of a field error which has already been
820-
added to the {"errors"} list in the response, the {"errors"} list must not be
821-
further affected. That is, only one error should be added to the errors list per
822-
field.
820+
added to the {"errors"} list in the _response map_, the {"errors"} list must not
821+
be further affected. That is, only one error should be added to the errors list
822+
per field.
823823

824824
Since `Non-Null` type fields cannot be {null}, field errors are propagated to be
825825
handled by the parent field. If the parent field may be {null} then it resolves
@@ -832,5 +832,5 @@ type is also wrapped in a `Non-Null`, the field error continues to propagate
832832
upwards.
833833

834834
If all fields from the root of the request to the source of the field error
835-
return `Non-Null` types, then the {"data"} entry in the response should be
835+
return `Non-Null` types, then the {"data"} entry in the _response map_ should be
836836
{null}.

spec/Section 7 -- Response.md

+39-36
Original file line numberDiff line numberDiff line change
@@ -10,71 +10,74 @@ the case that any _field error_ was raised on a field and was replaced with
1010

1111
## Response Format
1212

13-
A GraphQL request returns either a _response_ or a _response stream_.
13+
:: A GraphQL _response_ is either a _response map_ or a _response stream_.
1414

15-
### Response
15+
### Response Map
1616

17-
:: A GraphQL request returns a _response_ when the GraphQL operation is a query
18-
or mutation. A _response_ must be a map.
17+
:: A GraphQL request returns a _response map_ when the GraphQL operation is a
18+
query or mutation. When the GraphQL operation is a subscription, the GraphQL
19+
request returns a _response map_ if a _request error_ is raised. A response map
20+
must be a map.
1921

20-
If the request raised any errors, the response map must contain an entry with
22+
If the request raised any errors, the _response map_ must contain an entry with
2123
key `errors`. The value of this entry is described in the "Errors" section. If
2224
the request completed without raising any errors, this entry must not be
2325
present.
2426

25-
If the request included execution, the response map must contain an entry with
27+
If the request included execution, the _response map_ must contain an entry with
2628
key `data`. The value of this entry is described in the "Data" section. If the
2729
request failed before execution, due to a syntax error, missing information, or
2830
validation error, this entry must not be present.
2931

30-
The response map may also contain an entry with key `extensions`. This entry, if
31-
set, must have a map as its value. This entry is reserved for implementers to
32+
The _response map_ may also contain an entry with key `extensions`. This entry,
33+
if set, must have a map as its value. This entry is reserved for implementers to
3234
extend the protocol however they see fit, and hence there are no additional
3335
restrictions on its contents.
3436

3537
To ensure future changes to the protocol do not break existing services and
36-
clients, the top level response map must not contain any entries other than the
37-
three described above.
38+
clients, the top level _response map_ must not contain any entries other than
39+
the three described above.
3840

39-
Note: When `errors` is present in the response, it may be helpful for it to
40-
appear first when serialized to make it more clear when errors are present in a
41-
response during debugging.
41+
Note: When `errors` is present in the _response map_, it may be helpful for it
42+
to appear first when serialized to make it more clear when errors are present in
43+
a response map during debugging.
4244

4345
### Response Stream
4446

4547
:: A GraphQL request returns a _response stream_ when the GraphQL operation is a
46-
subscription. A _response stream_ must be a stream of _response_.
48+
subscription and a _request error_ is not raised. A response stream must be a
49+
stream of _response map_.
4750

4851
### Data
4952

50-
The `data` entry in the response will be the result of the execution of the
51-
requested operation. If the operation was a query, this output will be an object
52-
of the query root operation type; if the operation was a mutation, this output
53-
will be an object of the mutation root operation type.
53+
The `data` entry in the _response map_ will be the result of the execution of
54+
the requested operation. If the operation was a query, this output will be an
55+
object of the query root operation type; if the operation was a mutation, this
56+
output will be an object of the mutation root operation type.
5457

5558
If an error was raised before execution begins, the `data` entry should not be
56-
present in the response.
59+
present in the _response map_.
5760

58-
If an error was raised during the execution that prevented a valid response, the
59-
`data` entry in the response should be `null`.
61+
If an error was raised during execution that propagated to the operation root,
62+
the `data` entry in the _response map_ should be `null`.
6063

6164
### Errors
6265

63-
The `errors` entry in the response is a non-empty list of errors raised during
64-
the _request_, where each error is a map of data described by the error result
65-
format below.
66+
The `errors` entry in the _response map_ is a non-empty list of errors raised
67+
during the _request_, where each error is a map of data described by the error
68+
result format below.
6669

67-
If present, the `errors` entry in the response must contain at least one error.
68-
If no errors were raised during the request, the `errors` entry must not be
69-
present in the response.
70+
If present, the `errors` entry in the _response map_ must contain at least one
71+
error. If no errors were raised during the request, the `errors` entry must not
72+
be present in the response map.
7073

71-
If the `data` entry in the response is not present, the `errors` entry must be
72-
present. It must contain at least one _request error_ indicating why no data was
73-
able to be returned.
74+
If the `data` entry in the _response map_ is not present, the `errors` entry
75+
must be present. It must contain at least one _request error_ indicating why no
76+
data was able to be returned.
7477

75-
If the `data` entry in the response is present (including if it is the value
76-
{null}), the `errors` entry must be present if and only if one or more _field
77-
error_ was raised during execution.
78+
If the `data` entry in the _response map_ is present (including if it is the
79+
value {null}), the `errors` entry must be present if and only if one or more
80+
_field error_ was raised during execution.
7881

7982
**Request Errors**
8083

@@ -85,7 +88,7 @@ to determine which operation to execute, or invalid input values for variables.
8588

8689
A request error is typically the fault of the requesting client.
8790

88-
If a request error is raised, the `data` entry in the response must not be
91+
If a request error is raised, the `data` entry in the _response map_ must not be
8992
present, the `errors` entry must include the error, and request execution should
9093
be halted.
9194

@@ -99,8 +102,8 @@ A field error is typically the fault of a GraphQL service.
99102

100103
If a field error is raised, execution attempts to continue and a partial result
101104
is produced (see [Handling Field Errors](#sec-Handling-Field-Errors)). The
102-
`data` entry in the response must be present. The `errors` entry should include
103-
this error.
105+
`data` entry in the _response map_ must be present. The `errors` entry should
106+
include this error.
104107

105108
**Error Result Format**
106109

0 commit comments

Comments
 (0)