@@ -9,40 +9,59 @@ the case that any _execution error_ was raised and replaced with {null}.
9
9
10
10
## Response Format
11
11
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_ .
13
14
14
- ### Response
15
+ ### Execution Result
15
16
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_ .
18
20
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
22
34
present.
23
35
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.
28
38
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
33
40
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.
37
56
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.
41
59
42
60
### Response Stream
43
61
44
62
:: 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_ .
46
65
47
66
### Response Position
48
67
@@ -89,37 +108,25 @@ found at `["hero", "friends"]`, the hero's first friend at
89
108
90
109
### Data
91
110
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.
96
115
97
116
The response data is the result of accumulating the resolved result of all
98
117
response positions during execution.
99
118
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 .
102
121
103
122
If an error was raised during the execution that prevented a valid response, the
104
123
{"data"} entry in the response should be ` null ` .
105
124
106
125
### Errors
107
126
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.
123
130
124
131
** Request Errors**
125
132
@@ -130,9 +137,9 @@ to determine which operation to execute, or invalid input values for variables.
130
137
131
138
A request error is typically the fault of the requesting client.
132
139
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.
136
143
137
144
** Execution Errors**
138
145
@@ -307,6 +314,17 @@ discouraged.
307
314
}
308
315
```
309
316
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
+
310
328
## Serialization Format
311
329
312
330
GraphQL does not require a specific serialization format. However, clients
0 commit comments