Skip to content

Commit 6e9b3c3

Browse files
committed
Edit: Clarify list coercion rules
This adds some additional copy to list result coercion about handling errors and nullability for items, and clarified copy and new examples for input coercion to better clarify the single-item rule, recursive coercion, and null values. Fixes #372
1 parent 4b7e22b commit 6e9b3c3

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

spec/Section 3 -- Type System.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,26 +1398,47 @@ in square brackets like this: `pets: [Pet]`.
13981398

13991399
GraphQL servers must return an ordered list as the result of a list type. Each
14001400
item in the list must be the result of a result coercion of the item type. If a
1401-
reasonable coercion is not possible they must raise a field error. In
1401+
reasonable coercion is not possible it must raise a field error. In
14021402
particular, if a non-list is returned, the coercion should fail, as this
14031403
indicates a mismatch in expectations between the type system and the
14041404
implementation.
14051405

1406+
If a list's item type is nullable, then errors occuring during preparation or
1407+
coercion of an individual item in the list must result in a the value {null} at
1408+
that position in the list along with an error added to the response. If a list's
1409+
item type is non-null, an error occuring at an individual item in the list must
1410+
result in a field error for the entire list.
1411+
1412+
Note: For more information on the error handling process, see "Errors and
1413+
Non-Nullability" within the Execution section.
1414+
14061415
**Input Coercion**
14071416

14081417
When expected as an input, list values are accepted only when each item in the
14091418
list can be accepted by the list's item type.
14101419

14111420
If the value passed as an input to a list type is *not* a list and not the
1412-
{null} value, it should be coerced as though the input was a list of size one,
1413-
where the value passed is the only item in the list. This is to allow inputs
1414-
that accept a "var args" to declare their input type as a list; if only one
1415-
argument is passed (a common case), the client can just pass that value rather
1416-
than constructing the list.
1417-
1418-
Note that when a {null} value is provided via a runtime variable value for a
1419-
list type, the value is interpreted as no list being provided, and not a list of
1420-
size one with the value {null}.
1421+
{null} value, then the result of input coercion is a list of size one,
1422+
where the single item value is the result of input coercion for the list's item
1423+
type on the provided value (note this may apply recursively for nested lists).
1424+
1425+
This allow inputs which accept one or many arguments (sometimes referred to as
1426+
"var args") to declare their input type as a list while for the common case of a
1427+
single value, a client can just pass that value directly rather than
1428+
constructing the list.
1429+
1430+
Following are examples of input coercion with various list types and values:
1431+
1432+
Expected Type | Provided Value | Coerced Value
1433+
------------- | ---------------- | ---------------------------
1434+
`[Int]` | `[1, 2, 3]` | `[1, 2, 3]`
1435+
`[Int]` | `[1, "b", true]` | Error: Incorrect item value
1436+
`[Int]` | `1` | `[1]`
1437+
`[Int]` | `null` | `null`
1438+
`[[Int]]` | `[[1], [2, 3]]` | `[[1], [2, 3]`
1439+
`[[Int]]` | `[1, 2, 3]` | Error: Incorrect item value
1440+
`[[Int]]` | `1` | `[[1]]`
1441+
`[[Int]]` | `null` | `null`
14211442

14221443

14231444
## Non-Null

0 commit comments

Comments
 (0)