You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/Section 7 -- Response.md
+49-53Lines changed: 49 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,12 +17,12 @@ A GraphQL request returns either a _response_ or a _response stream_.
17
17
or mutation. A _response_ must be a map.
18
18
19
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
20
+
key {"errors". The value of this entry is described in the "Errors" section. If
21
21
the request completed without raising any errors, this entry must not be
22
22
present.
23
23
24
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
25
+
key {"data"}. The value of this entry is described in the "Data" section. If the
26
26
request failed before execution, due to a syntax error, missing information, or
27
27
validation error, this entry must not be present.
28
28
@@ -35,7 +35,7 @@ To ensure future changes to the protocol do not break existing services and
35
35
clients, the top level response map must not contain any entries other than the
36
36
three described above.
37
37
38
-
Note: When `errors` is present in the response, it may be helpful for it to
38
+
Note: When {"errors"} is present in the response, it may be helpful for it to
39
39
appear first when serialized to make it more clear when errors are present in a
40
40
response during debugging.
41
41
@@ -44,30 +44,27 @@ response during debugging.
44
44
:: A GraphQL request returns a _response stream_ when the GraphQL operation is a
45
45
subscription. A _response stream_ must be a stream of _response_.
46
46
47
-
### Data
48
-
49
-
The `data` entry in the response will be the result of the execution of the
50
-
requested operation. If the operation was a query, this output will be an object
51
-
of the query root operation type; if the operation was a mutation, this output
52
-
will be an object of the mutation root operation type.
53
-
54
-
If an error was raised before execution begins, the `data` entry should not be
55
-
present in the response.
56
-
57
-
If an error was raised during the execution that prevented a valid response, the
58
-
`data` entry in the response should be `null`.
47
+
### Response Position
59
48
60
-
**Response Position**
49
+
<aname="sec-Path">
50
+
<!-- Legacy link, this section was previously titled "Path" -->
51
+
</a>
61
52
62
53
:: A _response position_ is a uniquely identifiable position in the response
63
54
data produced during execution. It is either a direct entry in the {resultMap}
64
55
of a {ExecuteSelectionSet()}, or it is a position in a (potentially nested) List
65
-
value.
56
+
value. Each response position is uniquely identifiable via a _response path_.
66
57
67
-
The response data is the result of accumulating the result of all response
68
-
positions during execution.
58
+
:: A _response path_ uniquely identifies a _response position_ via a list of path segments (response keys or list indicies) starting at the root of the response and ending with the associated response position.
59
+
60
+
The value for a _response path_ must be a list of path segments. Path
61
+
segments that represent field response keys must be strings, and path segments that represent
62
+
list indices must be 0-indexed integers. If a path segment is associated with an
63
+
aliased field it must use the aliased name, since it represents a path in the
64
+
response, not in the request.
69
65
70
-
Each _response position_ is uniquely identifiable via a _path entry_.
66
+
When a _response path_ is present on an _error result_, it identifies the
67
+
_response position_ which raised the error.
71
68
72
69
A single field execution may result in multiple response positions. For example,
73
70
@@ -87,22 +84,38 @@ The hero's name would be found in the _response position_ identified by
87
84
`["hero", "friends"]`, the hero's first friend at `["hero", "friends", 0]` and
88
85
that friend's name at `["hero", "friends", 0, "name"]`.
89
86
87
+
### Data
88
+
89
+
The {"data"} entry in the response will be the result of the execution of the
90
+
requested operation. If the operation was a query, this output will be an object
91
+
of the query root operation type; if the operation was a mutation, this output
92
+
will be an object of the mutation root operation type.
93
+
94
+
The response data is the result of accumulating the resolved result of all
95
+
response positions during execution.
96
+
97
+
If an error was raised before execution begins, the {"data"} entry should not be
98
+
present in the response.
99
+
100
+
If an error was raised during the execution that prevented a valid response, the
101
+
{"data"} entry in the response should be `null`.
102
+
90
103
### Errors
91
104
92
-
The `errors` entry in the response is a non-empty list of errors raised during
105
+
The {"errors"} entry in the response is a non-empty list of errors raised during
93
106
the _request_, where each error is a map of data described by the error result
94
107
format below.
95
108
96
-
If present, the `errors` entry in the response must contain at least one error.
97
-
If no errors were raised during the request, the `errors` entry must not be
109
+
If present, the {"errors"} entry in the response must contain at least one error.
110
+
If no errors were raised during the request, the {"errors"} entry must not be
98
111
present in the response.
99
112
100
-
If the `data` entry in the response is not present, the `errors` entry must be
113
+
If the {"data"} entry in the response is not present, the {"errors"} entry must be
101
114
present. It must contain at least one _request error_ indicating why no data was
102
115
able to be returned.
103
116
104
-
If the `data` entry in the response is present (including if it is the value
105
-
{null}), the `errors` entry must be present if and only if one or more
117
+
If the {"data"} entry in the response is present (including if it is the value
118
+
{null}), the {"errors"} entry must be present if and only if one or more
106
119
_execution error_ was raised during execution.
107
120
108
121
**Request Errors**
@@ -114,8 +127,8 @@ to determine which operation to execute, or invalid input values for variables.
114
127
115
128
A request error is typically the fault of the requesting client.
116
129
117
-
If a request error is raised, the `data` entry in the response must not be
118
-
present, the `errors` entry must include the error, and request execution should
130
+
If a request error is raised, the {"data"} entry in the response must not be
131
+
present, the {"errors"} entry must include the error, and request execution should
119
132
be halted.
120
133
121
134
**Execution Errors**
@@ -136,31 +149,29 @@ An execution error is typically the fault of a GraphQL service.
136
149
137
150
An _execution error_ must occur at a specific _response position_, and may occur
138
151
in any response position. The response position of an execution error is
139
-
indicated via the error's `path`_path entry_.
152
+
indicated via a _response path_ in the error response's {"path"} entry.
140
153
141
154
When an execution error is raised at a given _response position_, then that
142
-
response position must not be present within the _response_`data` entry (except
143
-
{null}), and the `errors` entry must include the error. Nested execution is
155
+
response position must not be present within the _response_{"data"} entry (except
156
+
{null}), and the {"errors"} entry must include the error. Nested execution is
144
157
halted and sibling execution attempts to continue, producing partial result (see
Every error must contain an entry with the key `message` with a string
162
+
Every error must contain an entry with the key {"message"} with a string
150
163
description of the error intended for the developer as a guide to understand and
151
164
correct the error.
152
165
153
166
If an error can be associated to a particular point in the requested GraphQL
154
-
document, it should contain an entry with the key `locations` with a list of
155
-
locations, where each location is a map with the keys `line` and `column`, both
167
+
document, it should contain an entry with the key {"locations"} with a list of
168
+
locations, where each location is a map with the keys {"line"} and {"column"}, both
156
169
positive numbers starting from `1` which describe the beginning of an associated
157
170
syntax element.
158
171
159
172
If an error can be associated to a particular field in the GraphQL result, it
160
-
must contain an entry with the key `path` that details the path of the response
161
-
field which experienced the error. This allows clients to identify whether a
162
-
`null` result is intentional or caused by a runtime error. The value of this
163
-
_path entry_ is described in the [Path](#sec-Path) section.
173
+
must contain an entry with the key {"path"} with a _response path_ which describes which _response position_ which experienced the error. This allows clients to identify whether a
174
+
{null} resolved result is a true value or the result of an _execution error_.
164
175
165
176
For example, if fetching one of the friends' names fails in the following
166
177
operation:
@@ -290,21 +301,6 @@ discouraged.
290
301
}
291
302
```
292
303
293
-
### Path
294
-
295
-
:: A _path entry_ is an entry within an _error result_ that indicates the
296
-
_response position_ at which the error occurred.
297
-
298
-
The value for a _path entry_ must be a list of path segments starting at the
299
-
root of the response and ending with the field to be associated with. Path
300
-
segments that represent fields must be strings, and path segments that represent
301
-
list indices must be 0-indexed integers. If a path segment is associated with an
302
-
aliased field it must use the aliased name, since it represents a path in the
303
-
response, not in the request.
304
-
305
-
When the _path entry_ is present on an _error result_, it identifies the
306
-
response field which experienced the error.
307
-
308
304
## Serialization Format
309
305
310
306
GraphQL does not require a specific serialization format. However, clients
0 commit comments