Skip to content

Commit eb86ed9

Browse files
spawnialeebyron
andauthored
Disallow non-breakable chains of circular references in Input Objects (#701)
* Disallow non-breakable chains of circular references in Input Objects * Editorial changes * Editorial Co-authored-by: Lee Byron <[email protected]>
1 parent c83baf6 commit eb86ed9

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

spec/Section 3 -- Type System.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,60 @@ define arguments or contain references to interfaces and unions, neither of
14481448
which is appropriate for use as an input argument. For this reason, input
14491449
objects have a separate type in the system.
14501450

1451+
**Circular References**
1452+
1453+
Input Objects are allowed to reference other Input Objects as field types. A
1454+
circular reference occurs when an Input Object references itself either directly
1455+
or through referenced Input Objects.
1456+
1457+
Circular references are generally allowed, however they may not be defined as an
1458+
unbroken chain of Non-Null singular fields. Such Input Objects are invalid
1459+
because there is no way to provide a legal value for them.
1460+
1461+
This example of a circularly-referenced input type is valid as the field `self`
1462+
may be omitted or the value {null}.
1463+
1464+
```graphql example
1465+
input Example {
1466+
self: Example
1467+
value: String
1468+
}
1469+
```
1470+
1471+
This example is also valid as the field `self` may be an empty List.
1472+
1473+
```graphql example
1474+
input Example {
1475+
self: [Example!]!
1476+
value: String
1477+
}
1478+
```
1479+
1480+
This example of a circularly-referenced input type is invalid as the field
1481+
`self` cannot be provided a finite value.
1482+
1483+
```graphql counter-example
1484+
input Example {
1485+
value: String
1486+
self: Example!
1487+
}
1488+
```
1489+
1490+
This example is also invalid, as there is a non-null singular circular reference
1491+
via the `First.second` and `Second.first` fields.
1492+
1493+
```graphql counter-example
1494+
input First {
1495+
second: Second!
1496+
value: String
1497+
}
1498+
1499+
input Second {
1500+
first: First!
1501+
value: String
1502+
}
1503+
```
1504+
14511505
**Result Coercion**
14521506

14531507
An input object is never a valid result. Input Object types cannot be the return
@@ -1526,6 +1580,9 @@ Literal Value | Variables | Coerced Value
15261580
characters {"__"} (two underscores).
15271581
3. The input field must accept a type where {IsInputType(inputFieldType)}
15281582
returns {true}.
1583+
3. If an Input Object references itself either directly or through referenced
1584+
Input Objects, at least one of the fields in the chain of references must be
1585+
either a nullable or a List type.
15291586

15301587

15311588
### Input Object Extensions

0 commit comments

Comments
 (0)