Skip to content

Commit c63b6a5

Browse files
committed
Add sub-sections for 'request errors' and 'field errors' and update links
1 parent b66f783 commit c63b6a5

File tree

3 files changed

+54
-28
lines changed

3 files changed

+54
-28
lines changed

spec/Section 3 -- Type System.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ A GraphQL schema may describe that a field represents a list of another type;
280280
the `List` type is provided for this reason, and wraps another type.
281281

282282
Similarly, the `Non-Null` type wraps another type, and denotes that the
283-
resulting value will never be {null} (and that an error cannot result in a
283+
resulting value will never be {null} (and that a field error cannot result in a
284284
{null} value).
285285

286286
These two types are referred to as "wrapping types"; non-wrapping types are
@@ -375,7 +375,8 @@ all built-in scalars must be omitted for brevity.
375375

376376
A GraphQL service, when preparing a field of a given scalar type, must uphold the
377377
contract the scalar type describes, either by coercing the value or producing a
378-
field error if a value cannot be coerced or if coercion may result in data loss.
378+
[field error](#sec-Errors.Field-errors) if a value cannot be coerced or if
379+
coercion may result in data loss.
379380

380381
A GraphQL service may decide to allow coercing different internal types to the
381382
expected return type. For example when coercing a field of type {Int} a boolean
@@ -399,7 +400,8 @@ information on the serialization of scalars in common JSON and other formats.
399400

400401
If a GraphQL service expects a scalar type as input to an argument, coercion
401402
is observable and the rules must be well defined. If an input value does not
402-
match a coercion rule, a [request error](#sec-Request-Errors) must be raised.
403+
match a coercion rule, a [request error](#sec-Errors.Request-errors) must be
404+
raised (input values are validated before execution begins).
403405

404406
GraphQL has different constant literals to represent integer and floating-point
405407
input values, and coercion rules may apply differently depending on which type
@@ -1516,8 +1518,8 @@ type of an Object or Interface field.
15161518
The value for an input object should be an input object literal or an unordered
15171519
map supplied by a variable, otherwise a request error must be raised. In either
15181520
case, the input object literal or unordered map must not contain any entries
1519-
with names not defined by a field of this input object type, otherwise an error
1520-
must be raised.
1521+
with names not defined by a field of this input object type, otherwise a
1522+
response error must be raised.
15211523

15221524
The result of coercion is an unordered map with an entry for each field both
15231525
defined by the input object type and for which a value exists. The resulting map
@@ -1632,12 +1634,12 @@ implementation.
16321634

16331635
If a list's item type is nullable, then errors occurring during preparation or
16341636
coercion of an individual item in the list must result in a the value {null} at
1635-
that position in the list along with an error added to the response. If a list's
1636-
item type is non-null, an error occurring at an individual item in the list must
1637-
result in a field error for the entire list.
1637+
that position in the list along with a field error added to the response.
1638+
If a list's item type is non-null, a field error occurring at an individual item
1639+
in the list must result in a field error for the entire list.
16381640

1639-
Note: For more information on the error handling process, see "Errors and
1640-
Non-Nullability" within the Execution section.
1641+
Note: See [Handling Field Errors](#sec-Handling-Field-Errors) for more about
1642+
this behavior.
16411643

16421644
**Input Coercion**
16431645

spec/Section 6 -- Execution.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ resolving to {null} if allowed or further propagated to a parent field.
347347
If this occurs, any sibling fields which have not yet executed or have not yet
348348
yielded a value may be cancelled to avoid unnecessary work.
349349

350-
See the [Errors and Non-Nullability](#sec-Errors-and-Non-Nullability) section
351-
of Field Execution for more about this behavior.
350+
Note: See [Handling Field Errors](#sec-Handling-Field-Errors) for more about
351+
this behavior.
352352

353353
### Normal and Serial Execution
354354

@@ -714,19 +714,27 @@ MergeSelectionSets(fields):
714714
* Return {selectionSet}.
715715

716716

717-
### Errors and Non-Nullability
717+
### Handling Field Errors
718718

719-
If an error is raised while resolving a field, it should be treated as though
720-
the field returned {null}, and an error must be added to the {"errors"} list
721-
in the response.
719+
["Field errors"](#sec-Errors.Field-errors) are raised from a particular field
720+
during value resolution or coercion. While these errors should be reported in
721+
the response, they are "handled" by producing a partial response.
722+
723+
Note: This is distinct from ["request errors"](#sec-Errors.Request-errors) which
724+
are raised before execution begins. If a request error is encountered, execution
725+
does not begin and no data is returned in the response.
726+
727+
If a field error is raised while resolving a field, it is handled as though the
728+
field returned {null}, and the error must be added to the {"errors"} list in
729+
the response.
722730

723731
If the result of resolving a field is {null} (either because the function to
724-
resolve the field returned {null} or because an error occurred), and that
732+
resolve the field returned {null} or because a field error was raised), and that
725733
field is of a `Non-Null` type, then a field error is raised. The
726734
error must be added to the {"errors"} list in the response.
727735

728-
If the field returns {null} because of an error which has already been added to
729-
the {"errors"} list in the response, the {"errors"} list must not be
736+
If the field returns {null} because of a field error which has already been
737+
added to the {"errors"} list in the response, the {"errors"} list must not be
730738
further affected. That is, only one error should be added to the errors list per
731739
field.
732740

spec/Section 7 -- Response.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@ operation if successful, and describes any errors raised during the request.
77
A response may contain both a partial response as well as any field errors in
88
the case that a field error was raised on a field and was replaced with {null}.
99

10-
## Request Errors
11-
12-
Any errors raised during a GraphQL request are termed "request errors."
13-
Request errors are not limited to errors that were raised during execution of the
14-
operation, they could be raised during parsing and validation of the request
15-
too. For example, a request error will be raised if the request does not
16-
contain sufficient information to indicate uniquely which operation to execute.
17-
1810
## Response Format
1911

2012
A response to a GraphQL request must be a map.
2113

2214
If the request raised any errors, the response map must contain an
2315
entry with key `errors`. The value of this entry is described in the "Errors"
24-
section. If the operation completed without raising any errors, this entry
16+
section. If the request completed without raising any errors, this entry
2517
must not be present.
2618

2719
If the request included execution, the response map must contain an entry
@@ -73,6 +65,30 @@ If the `data` entry in the response is present (including if it is the value
7365
were raised during execution. If field errors were raised during execution, it
7466
should contain those errors.
7567

68+
**Request errors**
69+
70+
Request errors are raised before execution begins. This may occur due to a parse
71+
grammar or validation error in the requested document, an inability to determine
72+
which operation to execute, or invalid input values for variables.
73+
74+
Request errors are typically the fault of the requesting client.
75+
76+
If a request error is raised, execution does not begin and the `data` entry in
77+
the response must not be present. The `errors` entry must include the error.
78+
79+
**Field errors**
80+
81+
Field errors are raised during execution from a particular field. This may occur
82+
due to an internal error during value resolution or failure to coerce the
83+
resulting value.
84+
85+
Field errors are typically the fault of GraphQL service.
86+
87+
If a field error is raised, execution attempts to continue and a partial result
88+
is produced (see [Handling Field Errors](#sec-Handling-Field-Errors)).
89+
The `data` entry in the response must be present. The `errors` entry should
90+
include all raised field errors.
91+
7692
**Error result format**
7793

7894
Every error must contain an entry with the key `message` with a string

0 commit comments

Comments
 (0)