Skip to content

Commit f2b4d37

Browse files
committed
Define "execution result" and "request error result"
Signed-off-by: Rob Richard <rob@1stdibs.com>
1 parent 1f690d4 commit f2b4d37

File tree

2 files changed

+76
-57
lines changed

2 files changed

+76
-57
lines changed

spec/Section 6 -- Execution.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
310310

311311
- Let {responseStream} be a new _event stream_.
312312
- When {sourceStream} emits {sourceValue}:
313-
- Let {response} be the result of running
313+
- Let {executionResult} be the result of running
314314
{ExecuteSubscriptionEvent(subscription, schema, variableValues,
315315
sourceValue)}.
316316
- If internal {error} was raised:
317317
- Cancel {sourceStream}.
318-
- Complete {responseStream} with {error}.
318+
- Complete {executionResult} with {error}.
319319
- Otherwise emit {response} on {responseStream}.
320320
- When {sourceStream} completes normally:
321321
- Complete {responseStream} normally.
@@ -827,23 +827,24 @@ or coercion, at a specific _response position_. While these errors must be
827827
reported in the response, they are "handled" by producing partial {"data"} in
828828
the _response_.
829829

830-
Note: This is distinct from a _request error_ which results in a response with
831-
no data.
830+
Note: This is distinct from a _request error_ which results in a _request error
831+
result_ with no data.
832832

833833
If an execution error is raised while resolving a field (either directly or
834834
nested inside any lists), it is handled as though the _response position_ at
835835
which the error occurred resolved to {null}, and the error must be added to the
836-
{"errors"} list in the response.
836+
{"errors"} list in the _execution result_.
837837

838838
If the result of resolving a _response position_ is {null} (either due to the
839839
result of {ResolveFieldValue()} or because an execution error was raised), and
840840
that position is of a `Non-Null` type, then an execution error is raised at that
841-
position. The error must be added to the {"errors"} list in the response.
841+
position. The error must be added to the {"errors"} list in the _execution
842+
result_.
842843

843844
If a _response position_ resolves to {null} because of an execution error which
844-
has already been added to the {"errors"} list in the response, the {"errors"}
845-
list must not be further affected. That is, only one error should be added to
846-
the errors list per _response position_.
845+
has already been added to the {"errors"} list in the _execution result_, the
846+
{"errors"} list must not be further affected. That is, only one error should be
847+
added to the errors list per _response position_.
847848

848849
Since `Non-Null` response positions cannot be {null}, execution errors are
849850
propagated to be handled by the parent _response position_. If the parent
@@ -857,5 +858,5 @@ position_ must resolve to {null}. If the `List` type is also wrapped in a
857858
`Non-Null`, the execution error continues to propagate upwards.
858859

859860
If every _response position_ from the root of the request to the source of the
860-
execution error has a `Non-Null` type, then the {"data"} entry in the response
861-
should be {null}.
861+
execution error has a `Non-Null` type, then the {"data"} entry in the _execution
862+
result_ should be {null}.

spec/Section 7 -- Response.md

+64-46
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,59 @@ the case that any _execution error_ was raised and replaced with {null}.
99

1010
## Response Format
1111

12-
A GraphQL request returns either a _response_ or a _response stream_.
12+
:: A GraphQL request returns a _response_. A _response_ is either an _execution
13+
result_, a _request error result_, or a _response stream_.
1314

14-
### Response
15+
### Execution Result
1516

16-
:: A GraphQL request returns a _response_ when the GraphQL operation is a query
17-
or mutation. A _response_ must be a map.
17+
:: A GraphQL request returns an _execution result_ when the GraphQL operation is
18+
a query or mutation and the request included execution. Additionally, an
19+
execution result is the event emitted by a _response stream_.
1820

19-
If the request raised any errors, the response map must contain an entry with
20-
key {"errors"}. The value of this entry is described in the "Errors" section. If
21-
the request completed without raising any errors, this entry must not be
21+
An execution result must be map.
22+
23+
The _execution result_ must contain an entry with key {"data"}. The value of
24+
this entry is described in the "Data" section.
25+
26+
If execution raised any errors, the _execution result_ must contain an entry
27+
with key {"errors"}. The value of this entry must be a non-empty list of
28+
_execution error_ raised during execution. Each error must be a map as described
29+
in the "Errors" section below. If the request completed without raising any
30+
errors, this entry must not be present.
31+
32+
Note: When {"errors"} is present in a _execution result_, it may be helpful for
33+
it to appear first when serialized to make it more apparent that errors are
2234
present.
2335

24-
If the request included execution, the response map must contain an entry with
25-
key {"data"}. The value of this entry is described in the "Data" section. If the
26-
request failed before execution, due to a syntax error, missing information, or
27-
validation error, this entry must not be present.
36+
The _execution result_ may also contain an entry with key `extensions`. The
37+
value of this entry is described in the "Extensions" section.
2838

29-
The response map may also contain an entry with key `extensions`. This entry, if
30-
set, must have a map as its value. This entry is reserved for implementers to
31-
extend the protocol however they see fit, and hence there are no additional
32-
restrictions on its contents.
39+
### Request Error Result
3340

34-
To ensure future changes to the protocol do not break existing services and
35-
clients, the top level response map must not contain any entries other than the
36-
three described above.
41+
:: A GraphQL request returns a _request error result_ when the request fails
42+
before execution. A request may fail before execution due to a syntax error,
43+
missing information, or validation error, resulting in one or more _request
44+
error_ being raised. This request will result in no response data.
45+
46+
A request error result must be a map.
47+
48+
The _request error result_ map must contain an entry with key {"errors"}. The
49+
value of this entry must be a non-empty list of _request error_ raised during
50+
the _request_. It must contain at least one indicating why no data was able to
51+
be returned. Each error must be a map as described in the "Errors" section
52+
below.
53+
54+
Note: It may be helpful for the {"errors"} key to appear first when serialized
55+
to make it more apparent that errors are present.
3756

38-
Note: When {"errors"} is present in the response, it may be helpful for it to
39-
appear first when serialized to make it more clear when errors are present in a
40-
response during debugging.
57+
The _request error result_ map may also contain an entry with key `extensions`.
58+
The value of this entry is described in the "Extensions" section.
4159

4260
### Response Stream
4361

4462
:: A GraphQL request returns a _response stream_ when the GraphQL operation is a
45-
subscription. A _response stream_ must be a stream of _response_.
63+
subscription and the request included execution. A response stream must be a
64+
stream of _execution result_.
4665

4766
### Response Position
4867

@@ -89,37 +108,25 @@ found at `["hero", "friends"]`, the hero's first friend at
89108

90109
### Data
91110

92-
The {"data"} entry in the response will be the result of the execution of the
93-
requested operation. If the operation was a query, this output will be an object
94-
of the query root operation type; if the operation was a mutation, this output
95-
will be an object of the mutation root operation type.
111+
The {"data"} entry in the _execution result_ will be the result of the execution
112+
of the requested operation. If the operation was a query, this output will be an
113+
object of the query root operation type; if the operation was a mutation, this
114+
output will be an object of the mutation root operation type.
96115

97116
The response data is the result of accumulating the resolved result of all
98117
response positions during execution.
99118

100-
If an error was raised before execution begins, the {"data"} entry should not be
101-
present in the response.
119+
If an error was raised before execution begins, the _response_ must be a
120+
_request error result_. The {"data"} entry must not be present in this map.
102121

103122
If an error was raised during the execution that prevented a valid response, the
104123
{"data"} entry in the response should be `null`.
105124

106125
### Errors
107126

108-
The {"errors"} entry in the response is a non-empty list of errors raised during
109-
the _request_, where each error is a map of data described by the error result
110-
format below.
111-
112-
If present, the {"errors"} entry in the response must contain at least one
113-
error. If no errors were raised during the request, the {"errors"} entry must
114-
not be present in the response.
115-
116-
If the {"data"} entry in the response is not present, the {"errors"} entry must
117-
be present. It must contain at least one _request error_ indicating why no data
118-
was able to be returned.
119-
120-
If the {"data"} entry in the response is present (including if it is the value
121-
{null}), the {"errors"} entry must be present if and only if one or more
122-
_execution error_ was raised during execution.
127+
The {"errors"} entry in the _execution result_ or _request error result_ is a
128+
non-empty list of errors raised during the _request_, where each error is a map
129+
of data described by the error result format below.
123130

124131
**Request Errors**
125132

@@ -130,9 +137,9 @@ to determine which operation to execute, or invalid input values for variables.
130137

131138
A request error is typically the fault of the requesting client.
132139

133-
If a request error is raised, the {"data"} entry in the response must not be
134-
present, the {"errors"} entry must include the error, and request execution
135-
should be halted.
140+
If a request error is raised, the _response_ must be a _request error result_.
141+
The {"data"} entry in this map must not be present, the {"errors"} entry must
142+
include the error, and request execution should be halted.
136143

137144
**Execution Errors**
138145

@@ -307,6 +314,17 @@ discouraged.
307314
}
308315
```
309316

317+
### Extensions
318+
319+
The {"extensions"} entry in an _execution result_ or _request error result_, if
320+
set, must have a map as its value. This entry is reserved for implementers to
321+
extend the protocol however they see fit, and hence there are no additional
322+
restrictions on its contents.
323+
324+
To ensure future changes to the protocol do not break existing services and
325+
clients, the _execution result_ and _request error result_ maps must not contain
326+
any entries other than those described above.
327+
310328
## Serialization Format
311329

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

0 commit comments

Comments
 (0)