Skip to content

Commit d4f6ad8

Browse files
committed
Disallow non-breakable chains of circular references in Input Objects
1 parent 6671989 commit d4f6ad8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

spec/Section 3 -- Type System.md

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

1450+
**Circular References**
1451+
1452+
Input Objects are allowed to reference other Input Objects. A circular reference
1453+
occurs when an Input Object references itself either directly or through
1454+
referenced Input Objects.
1455+
1456+
Circular references are generally allowed, however they may not be defined as an
1457+
unbroken chain of Non-Null fields. Such Input Objects are invalid, because there
1458+
is no way to provide a legal value for them.
1459+
1460+
The following examples are allowed:
1461+
1462+
```graphql example
1463+
input Example {
1464+
self: Example
1465+
value: String
1466+
}
1467+
```
1468+
1469+
This is fine because a value for `self` may simply be omitted from the arguments.
1470+
1471+
```graphql example
1472+
input Example {
1473+
self: [Example!]!
1474+
value: String
1475+
}
1476+
```
1477+
1478+
This also works as `self` can just contain an empty list.
1479+
1480+
The following examples are invalid:
1481+
1482+
```graphql counter-example
1483+
input Example {
1484+
value: String
1485+
self: Example!
1486+
}
1487+
```
1488+
1489+
```graphql counter-example
1490+
input First {
1491+
second: Second!
1492+
value: String
1493+
}
1494+
1495+
input Second {
1496+
first: First!
1497+
value: String
1498+
}
1499+
```
1500+
14501501
**Result Coercion**
14511502

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

15291583

15301584
### Input Object Extensions

0 commit comments

Comments
 (0)