Skip to content

Commit 9cb9a4b

Browse files
benjieleebyron
andauthored
Replace 'query error' with 'request error' (#803)
* Replace 'query error' with 'request error' * Add details about request errors * Also use consistent error verbs Saw "throw" / "raise" / "occur" / "encounter" - most dominant verb is "raise" so standardizing that. * Add sub-sections for 'request errors' and 'field errors' and update links Co-authored-by: Lee Byron <[email protected]>
1 parent 6dbef35 commit 9cb9a4b

File tree

4 files changed

+94
-62
lines changed

4 files changed

+94
-62
lines changed

spec/Section 3 -- Type System.md

Lines changed: 24 additions & 22 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 query error 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
@@ -438,10 +440,10 @@ greater than or equal to 2<sup>31</sup>, a field error should be raised.
438440
**Input Coercion**
439441

440442
When expected as an input type, only integer input values are accepted. All
441-
other input values, including strings with numeric content, must raise a query
443+
other input values, including strings with numeric content, must raise a request
442444
error indicating an incorrect type. If the integer input value represents a
443445
value less than -2<sup>31</sup> or greater than or equal to 2<sup>31</sup>, a
444-
query error should be raised.
446+
request error should be raised.
445447

446448
Note: Numeric integer values larger than 32-bit should either use String or a
447449
custom-defined Scalar type, as not all platforms and transports support
@@ -473,10 +475,10 @@ coerced to {Float} and must raise a field error.
473475
When expected as an input type, both integer and float input values are
474476
accepted. Integer input values are coerced to Float by adding an empty
475477
fractional part, for example `1.0` for the integer input value `1`. All
476-
other input values, including strings with numeric content, must raise a query
478+
other input values, including strings with numeric content, must raise a request
477479
error indicating an incorrect type. If the input value otherwise represents a
478480
value not representable by finite IEEE 754 (e.g. {NaN}, {Infinity}, or a value
479-
outside the available precision), a query error must be raised.
481+
outside the available precision), a request error must be raised.
480482

481483

482484
### String
@@ -498,7 +500,7 @@ string `"1"` for the integer `1`.
498500
**Input Coercion**
499501

500502
When expected as an input type, only valid UTF-8 string input values are
501-
accepted. All other input values must raise a query error indicating an
503+
accepted. All other input values must raise a request error indicating an
502504
incorrect type.
503505

504506

@@ -519,7 +521,7 @@ this may include returning `true` for non-zero numbers.
519521
**Input Coercion**
520522

521523
When expected as an input type, only boolean input values are accepted. All
522-
other input values must raise a query error indicating an incorrect type.
524+
other input values must raise a request error indicating an incorrect type.
523525

524526

525527
### ID
@@ -544,7 +546,7 @@ When coercion is not possible they must raise a field error.
544546
When expected as an input type, any string (such as `"4"`) or integer (such as
545547
`4` or `-4`) input value should be coerced to ID as appropriate for the ID
546548
formats a given GraphQL service expects. Any other input value, including float
547-
input values (such as `4.0`), must raise a query error indicating an incorrect
549+
input values (such as `4.0`), must raise a request error indicating an incorrect
548550
type.
549551

550552

@@ -1386,7 +1388,7 @@ reasonable coercion is not possible they must raise a field error.
13861388
**Input Coercion**
13871389

13881390
GraphQL has a constant literal to represent enum input values. GraphQL string
1389-
literals must not be accepted as an enum input and instead raise a query error.
1391+
literals must not be accepted as an enum input and instead raise a request error.
13901392

13911393
Query variable transport serializations which have a different representation
13921394
for non-string symbolic values (for example, [EDN](https://github.com/edn-format/edn))
@@ -1514,10 +1516,10 @@ type of an Object or Interface field.
15141516
**Input Coercion**
15151517

15161518
The value for an input object should be an input object literal or an unordered
1517-
map supplied by a variable, otherwise a query error must be thrown. In either
1519+
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 thrown.
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
@@ -1526,7 +1528,7 @@ is constructed with the following rules:
15261528
* If no value is provided for a defined input object field and that field
15271529
definition provides a default value, the default value should be used. If no
15281530
default value is provided and the input object field's type is non-null, an
1529-
error should be thrown. Otherwise, if the field is not required, then no entry
1531+
error should be raised. Otherwise, if the field is not required, then no entry
15301532
is added to the coerced unordered map.
15311533

15321534
* If the value {null} was provided for an input object field, and the field's
@@ -1540,7 +1542,7 @@ is constructed with the following rules:
15401542

15411543
* If a variable is provided for an input object field, the runtime value of that
15421544
variable must be used. If the runtime value is {null} and the field type
1543-
is non-null, a field error must be thrown. If no runtime value is provided,
1545+
is non-null, a field error must be raised. If no runtime value is provided,
15441546
the variable definition's default value should be used. If the variable
15451547
definition does not provide a default value, the input object field
15461548
definition's default value should be used.
@@ -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

@@ -1706,7 +1708,7 @@ the parent field. For more information on this process, see
17061708
If an argument or input-object field of a Non-Null type is not provided, is
17071709
provided with the literal value {null}, or is provided with a variable that was
17081710
either not provided a value at runtime, or was provided the value {null}, then
1709-
a query error must be raised.
1711+
a request error must be raised.
17101712

17111713
If the value provided to the Non-Null type is provided with a literal value
17121714
other than {null}, or a Non-Null variable value, it is coerced using the input

spec/Section 5 -- Validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,4 +2013,4 @@ query booleanArgQueryWithDefault($booleanArg: Boolean = true) {
20132013
```
20142014

20152015
Note: The value {null} could still be provided to such a variable at runtime.
2016-
A non-null argument must produce a field error if provided a {null} value.
2016+
A non-null argument must raise a field error if provided a {null} value.

spec/Section 6 -- Execution.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ GetOperation(document, operationName):
4141
* If {operationName} is {null}:
4242
* If {document} contains exactly one operation.
4343
* Return the Operation contained in the {document}.
44-
* Otherwise produce a query error requiring {operationName}.
44+
* Otherwise raise a request error requiring {operationName}.
4545
* Otherwise:
4646
* Let {operation} be the Operation named {operationName} in {document}.
47-
* If {operation} was not found, produce a query error.
47+
* If {operation} was not found, raise a request error.
4848
* Return {operation}.
4949

5050

@@ -71,7 +71,7 @@ result to avoid validating the same request again in the future.
7171

7272
If the operation has defined any variables, then the values for
7373
those variables need to be coerced using the input coercion rules
74-
of variable's declared type. If a query error is encountered during
74+
of variable's declared type. If a request error is encountered during
7575
input coercion of variable values, then the operation fails without
7676
execution.
7777

@@ -92,14 +92,14 @@ CoerceVariableValues(schema, operation, variableValues):
9292
* Add an entry to {coercedValues} named {variableName} with the
9393
value {defaultValue}.
9494
* Otherwise if {variableType} is a Non-Nullable type, and either {hasValue}
95-
is not {true} or {value} is {null}, throw a query error.
95+
is not {true} or {value} is {null}, raise a request error.
9696
* Otherwise if {hasValue} is true:
9797
* If {value} is {null}:
9898
* Add an entry to {coercedValues} named {variableName} with the
9999
value {null}.
100100
* Otherwise:
101101
* If {value} cannot be coerced according to the input coercion
102-
rules of {variableType}, throw a query error.
102+
rules of {variableType}, raise a request error.
103103
* Let {coercedValue} be the result of coercing {value} according to the
104104
input coercion rules of {variableType}.
105105
* Add an entry to {coercedValues} named {variableName} with the
@@ -253,7 +253,7 @@ CreateSourceEventStream(subscription, schema, variableValues, initialValue):
253253
* Let {selectionSet} be the top level Selection Set in {subscription}.
254254
* Let {groupedFieldSet} be the result of
255255
{CollectFields(subscriptionType, selectionSet, variableValues)}.
256-
* If {groupedFieldSet} does not have exactly one entry, throw a query error.
256+
* If {groupedFieldSet} does not have exactly one entry, raise a request error.
257257
* Let {fields} be the value of the first entry in {groupedFieldSet}.
258258
* Let {fieldName} be the name of the first entry in {fields}.
259259
Note: This value is unaffected if an alias is used.
@@ -340,15 +340,15 @@ is explained in greater detail in the Field Collection section below.
340340

341341
**Errors and Non-Null Fields**
342342

343-
If during {ExecuteSelectionSet()} a field with a non-null {fieldType} throws a
343+
If during {ExecuteSelectionSet()} a field with a non-null {fieldType} raises a
344344
field error then that error must propagate to this entire selection set, either
345345
resolving to {null} if allowed or further propagated to a parent field.
346346

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

@@ -590,7 +590,7 @@ CoerceArgumentValues(objectType, field, variableValues):
590590
* Add an entry to {coercedValues} named {argumentName} with the
591591
value {defaultValue}.
592592
* Otherwise if {argumentType} is a Non-Nullable type, and either {hasValue}
593-
is not {true} or {value} is {null}, throw a field error.
593+
is not {true} or {value} is {null}, raise a field error.
594594
* Otherwise if {hasValue} is true:
595595
* If {value} is {null}:
596596
* Add an entry to {coercedValues} named {argumentName} with the
@@ -600,7 +600,7 @@ CoerceArgumentValues(objectType, field, variableValues):
600600
value {value}.
601601
* Otherwise:
602602
* If {value} cannot be coerced according to the input coercion
603-
rules of {argumentType}, throw a field error.
603+
rules of {argumentType}, raise a field error.
604604
* Let {coercedValue} be the result of coercing {value} according to the
605605
input coercion rules of {argumentType}.
606606
* Add an entry to {coercedValues} named {argumentName} with the
@@ -645,12 +645,12 @@ CompleteValue(fieldType, fields, result, variableValues):
645645
* Let {innerType} be the inner type of {fieldType}.
646646
* Let {completedResult} be the result of calling
647647
{CompleteValue(innerType, fields, result, variableValues)}.
648-
* If {completedResult} is {null}, throw a field error.
648+
* If {completedResult} is {null}, raise a field error.
649649
* Return {completedResult}.
650650
* If {result} is {null} (or another internal value similar to {null} such as
651651
{undefined}), return {null}.
652652
* If {fieldType} is a List type:
653-
* If {result} is not a collection of values, throw a field error.
653+
* If {result} is not a collection of values, raise a field error.
654654
* Let {innerType} be the inner type of {fieldType}.
655655
* Return a list where each list item is the result of calling
656656
{CompleteValue(innerType, fields, resultItem, variableValues)}, where
@@ -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 thrown 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
725-
field is of a `Non-Null` type, then a field error is thrown. The
732+
resolve the field returned {null} or because a field error was raised), and that
733+
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

0 commit comments

Comments
 (0)