Skip to content

Commit 8323576

Browse files
Editorial: Error Terminology
Uses the definition syntax to set definitions for "field error" and "request error", and uses italic references in every formal normative location as well as the first reference in each prose. Include links to other sections as set up in #957 Co-authored-by: Roman Ivantsov <[email protected]>
1 parent 9a96fc4 commit 8323576

4 files changed

+97
-89
lines changed

spec/Section 3 -- Type System.md

+50-47
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ A GraphQL schema may describe that a field represents a list of another type;
300300
the `List` type is provided for this reason, and wraps another type.
301301

302302
Similarly, the `Non-Null` type wraps another type, and denotes that the
303-
resulting value will never be {null} (and that a field error cannot result in a
304-
{null} value).
303+
resulting value will never be {null} (and that a _field error_ cannot result in
304+
a {null} value).
305305

306306
These two types are referred to as "wrapping types"; non-wrapping types are
307307
referred to as "named types". A wrapping type has an underlying named type,
@@ -425,14 +425,14 @@ examples in their description.
425425

426426
A GraphQL service, when preparing a field of a given scalar type, must uphold
427427
the contract the scalar type describes, either by coercing the value or
428-
producing a [field error](#sec-Errors.Field-errors) if a value cannot be coerced
429-
or if coercion may result in data loss.
428+
producing a _field error_ if a value cannot be coerced or if coercion may result
429+
in data loss.
430430

431431
A GraphQL service may decide to allow coercing different internal types to the
432432
expected return type. For example when coercing a field of type {Int} a boolean
433433
{true} value may produce {1} or a string value {"123"} may be parsed as base-10
434434
{123}. However if internal type coercion cannot be reasonably performed without
435-
losing information, then it must raise a field error.
435+
losing information, then it must raise a _field error_.
436436

437437
Since this coercion behavior is not observable to clients of the GraphQL
438438
service, the precise rules of coercion are left to the implementation. The only
@@ -450,8 +450,8 @@ information on the serialization of scalars in common JSON and other formats.
450450

451451
If a GraphQL service expects a scalar type as input to an argument, coercion is
452452
observable and the rules must be well defined. If an input value does not match
453-
a coercion rule, a [request error](#sec-Errors.Request-errors) must be raised
454-
(input values are validated before execution begins).
453+
a coercion rule, a _request error_ must be raised (input values are validated
454+
before execution begins).
455455

456456
GraphQL has different constant literals to represent integer and floating-point
457457
input values, and coercion rules may apply differently depending on which type
@@ -477,22 +477,23 @@ Fields returning the type {Int} expect to encounter 32-bit integer internal
477477
values.
478478

479479
GraphQL services may coerce non-integer internal values to integers when
480-
reasonable without losing information, otherwise they must raise a field error.
481-
Examples of this may include returning `1` for the floating-point number `1.0`,
482-
or returning `123` for the string `"123"`. In scenarios where coercion may lose
483-
data, raising a field error is more appropriate. For example, a floating-point
484-
number `1.2` should raise a field error instead of being truncated to `1`.
480+
reasonable without losing information, otherwise they must raise a _field
481+
error_. Examples of this may include returning `1` for the floating-point number
482+
`1.0`, or returning `123` for the string `"123"`. In scenarios where coercion
483+
may lose data, raising a field error is more appropriate. For example, a
484+
floating-point number `1.2` should raise a field error instead of being
485+
truncated to `1`.
485486

486487
If the integer internal value represents a value less than -2<sup>31</sup> or
487-
greater than or equal to 2<sup>31</sup>, a field error should be raised.
488+
greater than or equal to 2<sup>31</sup>, a _field error_ should be raised.
488489

489490
**Input Coercion**
490491

491492
When expected as an input type, only integer input values are accepted. All
492493
other input values, including strings with numeric content, must raise a request
493494
error indicating an incorrect type. If the integer input value represents a
494495
value less than -2<sup>31</sup> or greater than or equal to 2<sup>31</sup>, a
495-
request error should be raised.
496+
_request error_ should be raised.
496497

497498
Note: Numeric integer values larger than 32-bit should either use String or a
498499
custom-defined Scalar type, as not all platforms and transports support encoding
@@ -511,22 +512,22 @@ Fields returning the type {Float} expect to encounter double-precision
511512
floating-point internal values.
512513

513514
GraphQL services may coerce non-floating-point internal values to {Float} when
514-
reasonable without losing information, otherwise they must raise a field error.
515-
Examples of this may include returning `1.0` for the integer number `1`, or
516-
`123.0` for the string `"123"`.
515+
reasonable without losing information, otherwise they must raise a _field
516+
error_. Examples of this may include returning `1.0` for the integer number `1`,
517+
or `123.0` for the string `"123"`.
517518

518519
Non-finite floating-point internal values ({NaN} and {Infinity}) cannot be
519-
coerced to {Float} and must raise a field error.
520+
coerced to {Float} and must raise a _field error_.
520521

521522
**Input Coercion**
522523

523524
When expected as an input type, both integer and float input values are
524525
accepted. Integer input values are coerced to Float by adding an empty
525526
fractional part, for example `1.0` for the integer input value `1`. All other
526-
input values, including strings with numeric content, must raise a request error
527-
indicating an incorrect type. If the input value otherwise represents a value
528-
not representable by finite IEEE 754 (e.g. {NaN}, {Infinity}, or a value outside
529-
the available precision), a request error must be raised.
527+
input values, including strings with numeric content, must raise a _request
528+
error_ indicating an incorrect type. If the input value otherwise represents a
529+
value not representable by finite IEEE 754 (e.g. {NaN}, {Infinity}, or a value
530+
outside the available precision), a _request error_ must be raised.
530531

531532
### String
532533

@@ -542,14 +543,14 @@ that representation must be used to serialize this type.
542543
Fields returning the type {String} expect to encounter Unicode string values.
543544

544545
GraphQL services may coerce non-string raw values to {String} when reasonable
545-
without losing information, otherwise they must raise a field error. Examples of
546-
this may include returning the string `"true"` for a boolean true value, or the
547-
string `"1"` for the integer `1`.
546+
without losing information, otherwise they must raise a _field error_. Examples
547+
of this may include returning the string `"true"` for a boolean true value, or
548+
the string `"1"` for the integer `1`.
548549

549550
**Input Coercion**
550551

551552
When expected as an input type, only valid Unicode string input values are
552-
accepted. All other input values must raise a request error indicating an
553+
accepted. All other input values must raise a _request error_ indicating an
553554
incorrect type.
554555

555556
### Boolean
@@ -563,13 +564,13 @@ representation of the integers `1` and `0`.
563564
Fields returning the type {Boolean} expect to encounter boolean internal values.
564565

565566
GraphQL services may coerce non-boolean raw values to {Boolean} when reasonable
566-
without losing information, otherwise they must raise a field error. Examples of
567-
this may include returning `true` for non-zero numbers.
567+
without losing information, otherwise they must raise a _field error_. Examples
568+
of this may include returning `true` for non-zero numbers.
568569

569570
**Input Coercion**
570571

571572
When expected as an input type, only boolean input values are accepted. All
572-
other input values must raise a request error indicating an incorrect type.
573+
other input values must raise a _request error_ indicating an incorrect type.
573574

574575
### ID
575576

@@ -586,15 +587,15 @@ large 128-bit random numbers, to base64 encoded values, or string values of a
586587
format like [GUID](https://en.wikipedia.org/wiki/Globally_unique_identifier).
587588

588589
GraphQL services should coerce as appropriate given the ID formats they expect.
589-
When coercion is not possible they must raise a field error.
590+
When coercion is not possible they must raise a _field error_.
590591

591592
**Input Coercion**
592593

593594
When expected as an input type, any string (such as `"4"`) or integer (such as
594595
`4` or `-4`) input value should be coerced to ID as appropriate for the ID
595596
formats a given GraphQL service expects. Any other input value, including float
596-
input values (such as `4.0`), must raise a request error indicating an incorrect
597-
type.
597+
input values (such as `4.0`), must raise a _request error_ indicating an
598+
incorrect type.
598599

599600
### Scalar Extensions
600601

@@ -1448,7 +1449,7 @@ enum Direction {
14481449
**Result Coercion**
14491450

14501451
GraphQL services must return one of the defined set of possible values. If a
1451-
reasonable coercion is not possible they must raise a field error.
1452+
reasonable coercion is not possible they must raise a _field error_.
14521453

14531454
**Input Coercion**
14541455

@@ -1584,9 +1585,9 @@ type of an Object or Interface field.
15841585
**Input Coercion**
15851586

15861587
The value for an input object should be an input object literal or an unordered
1587-
map supplied by a variable, otherwise a request error must be raised. In either
1588-
case, the input object literal or unordered map must not contain any entries
1589-
with names not defined by a field of this input object type, otherwise a
1588+
map supplied by a variable, otherwise a _request error_ must be raised. In
1589+
either case, the input object literal or unordered map must not contain any
1590+
entries with names not defined by a field of this input object type, otherwise a
15901591
response error must be raised.
15911592

15921593
The result of coercion is an unordered map with an entry for each field both
@@ -1610,7 +1611,7 @@ is constructed with the following rules:
16101611

16111612
- If a variable is provided for an input object field, the runtime value of that
16121613
variable must be used. If the runtime value is {null} and the field type is
1613-
non-null, a field error must be raised. If no runtime value is provided, the
1614+
non-null, a _field error_ must be raised. If no runtime value is provided, the
16141615
variable definition's default value should be used. If the variable definition
16151616
does not provide a default value, the input object field definition's default
16161617
value should be used.
@@ -1698,13 +1699,14 @@ brackets like this: `pets: [Pet]`. Nesting lists is allowed: `matrix: [[Int]]`.
16981699

16991700
GraphQL services must return an ordered list as the result of a list type. Each
17001701
item in the list must be the result of a result coercion of the item type. If a
1701-
reasonable coercion is not possible it must raise a field error. In particular,
1702-
if a non-list is returned, the coercion should fail, as this indicates a
1703-
mismatch in expectations between the type system and the implementation.
1702+
reasonable coercion is not possible it must raise a _field error_. In
1703+
particular, if a non-list is returned, the coercion should fail, as this
1704+
indicates a mismatch in expectations between the type system and the
1705+
implementation.
17041706

17051707
If a list's item type is nullable, then errors occurring during preparation or
17061708
coercion of an individual item in the list must result in a the value {null} at
1707-
that position in the list along with a field error added to the response. If a
1709+
that position in the list along with a _field error_ added to the response. If a
17081710
list's item type is non-null, a field error occurring at an individual item in
17091711
the list must result in a field error for the entire list.
17101712

@@ -1764,19 +1766,20 @@ always optional and non-null types are always required.
17641766
In all of the above result coercions, {null} was considered a valid value. To
17651767
coerce the result of a Non-Null type, the coercion of the wrapped type should be
17661768
performed. If that result was not {null}, then the result of coercing the
1767-
Non-Null type is that result. If that result was {null}, then a field error must
1768-
be raised.
1769+
Non-Null type is that result. If that result was {null}, then a _field error_
1770+
must be raised.
17691771

1770-
Note: When a field error is raised on a non-null value, the error propagates to
1771-
the parent field. For more information on this process, see "Errors and
1772-
Non-Nullability" within the Execution section.
1772+
Note: When a _field error_ is raised on a non-null value, the error propagates
1773+
to the parent field. For more information on this process, see
1774+
[Errors and Non-Null Fields](#sec-Executing-Selection-Sets.Errors-and-Non-Null-Fields)
1775+
within the Execution section.
17731776

17741777
**Input Coercion**
17751778

17761779
If an argument or input-object field of a Non-Null type is not provided, is
17771780
provided with the literal value {null}, or is provided with a variable that was
17781781
either not provided a value at runtime, or was provided the value {null}, then a
1779-
request error must be raised.
1782+
_request error_ must be raised.
17801783

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

spec/Section 5 -- Validation.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Validation
22

3-
A GraphQL service does not just verify if a request is syntactically correct,
4-
but also ensures that it is unambiguous and mistake-free in the context of a
5-
given GraphQL schema.
3+
GraphQL does not just verify if a request is syntactically correct, but also
4+
ensures that it is unambiguous and mistake-free in the context of a given
5+
GraphQL schema.
66

77
An invalid request is still technically executable, and will always produce a
88
stable result as defined by the algorithms in the Execution section, however
@@ -2005,4 +2005,4 @@ query booleanArgQueryWithDefault($booleanArg: Boolean = true) {
20052005
```
20062006

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

0 commit comments

Comments
 (0)