Skip to content

Commit b1d308b

Browse files
authored
Clarify: Combining List and Non-Null (#440)
As pointed out in #228 this clarifying point should not be contained in the introspection system. Instead this makes more sense in the context of the type system definitions. Also expands to include coercion examples mirroring the list examples above. Closes #228
1 parent 42aeb94 commit b1d308b

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

spec/Section 3 -- Type System.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,39 @@ a non-null input type as invalid.
15171517
1. A Non-Null type must not wrap another Non-Null type.
15181518

15191519

1520+
### Combining List and Non-Null
1521+
1522+
The List and Non-Null wrapping types can compose, representing more complex
1523+
types. The rules for result coercion and input coercion of Lists and Non-Null
1524+
types apply in a recursive fashion.
1525+
1526+
For example if the inner item type of a List is Non-Null (e.g. `[T!]`), then
1527+
that List may not contain any {null} items. However if the inner type of a
1528+
Non-Null is a List (e.g. `[T]!`), then {null} is not accepted however an empty
1529+
list is accepted.
1530+
1531+
Following are examples of result coercion with various types and values:
1532+
1533+
Expected Type | Internal Value | Coerced Result
1534+
------------- | ---------------- | ---------------------------
1535+
`[Int]` | `[1, 2, 3]` | `[1, 2, 3]`
1536+
`[Int]` | `null` | `null`
1537+
`[Int]` | `[1, 2, null]` | `[1, 2, null]`
1538+
`[Int]` | `[1, 2, Error]` | `[1, 2, null]` (With logged error)
1539+
`[Int]!` | `[1, 2, 3]` | `[1, 2, 3]`
1540+
`[Int]!` | `null` | Error: Value cannot be null
1541+
`[Int]!` | `[1, 2, null]` | `[1, 2, null]`
1542+
`[Int]!` | `[1, 2, Error]` | `[1, 2, null]` (With logged error)
1543+
`[Int!]` | `[1, 2, 3]` | `[1, 2, 3]`
1544+
`[Int!]` | `null` | `null`
1545+
`[Int!]` | `[1, 2, null]` | `null` (With logged coercion error)
1546+
`[Int!]` | `[1, 2, Error]` | `null` (With logged error)
1547+
`[Int!]!` | `[1, 2, 3]` | `[1, 2, 3]`
1548+
`[Int!]!` | `null` | Error: Value cannot be null
1549+
`[Int!]!` | `[1, 2, null]` | Error: Item cannot be null
1550+
`[Int!]!` | `[1, 2, Error]` | Error: Error occurred in item
1551+
1552+
15201553
## Directives
15211554

15221555
DirectiveDefinition : Description? directive @ Name ArgumentsDefinition? on DirectiveLocations

spec/Section 4 -- Introspection.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,6 @@ required inputs for arguments and input object fields.
361361
* All other fields must return {null}.
362362

363363

364-
#### Combining List and Non-Null
365-
366-
List and Non-Null can compose, representing more complex types.
367-
368-
If the modified type of a List is Non-Null, then that List may not contain any
369-
{null} items.
370-
371-
If the modified type of a Non-Null is List, then {null} is not accepted,
372-
however an empty list is accepted.
373-
374-
If the modified type of a List is a List, then each item in the first List is
375-
another List of the second List's type.
376-
377-
A Non-Null type cannot modify another Non-Null type.
378-
379-
380364
### The __Field Type
381365

382366
The `__Field` type represents each field in an Object or Interface type.

0 commit comments

Comments
 (0)