Skip to content

Commit 39227d5

Browse files
author
spawnia
committed
Add rules for how circular references in Input Objects are handled graphql#189
1 parent 06614fb commit 39227d5

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

spec/Section 3 -- Type System.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,57 @@ Literal Value | Variables | Coerced Value
13601360

13611361
**Type Validation**
13621362

1363-
1. An Input Object type must define one or more input fields.
1364-
2. The fields of an Input Object type must have unique names within that
1365-
Input Object type; no two fields may share the same name.
1366-
3. The return types of each defined field must be an Input type.
1363+
* An Input Object type must define one or more input fields.
1364+
* The fields of an Input Object type must have unique names within that
1365+
Input Object type; no two fields may share the same name.
1366+
* The return types of each defined field must be an Input type.
13671367

1368+
Input Objects are generally allowed to reference other Input Objects, even itself.
1369+
If an Input Object references itself either directly or through subordinated
1370+
Input Objects, one of the fields in the chain of references must be either nullable
1371+
or a list. Input Objects with non-nullable circular references are invalid, because there
1372+
is no way to provide a legal value for them.
1373+
1374+
The following examples are allowed:
1375+
1376+
```graphql example
1377+
input Example {
1378+
value: String
1379+
self: Example
1380+
}
1381+
```
1382+
1383+
This is fine because `self` may simply omitted at any point in the chain.
1384+
1385+
```graphql example
1386+
input Example {
1387+
value: String
1388+
self: [Example!]!
1389+
}
1390+
```
1391+
1392+
This also works as `self` can just contain an empty list.
1393+
1394+
The following examples are invalid:
1395+
1396+
```graphql counter-example
1397+
input Example {
1398+
value: String
1399+
self: Example!
1400+
}
1401+
```
1402+
1403+
```graphql counter-example
1404+
input First {
1405+
second: Second!
1406+
string: String
1407+
}
1408+
1409+
input Second {
1410+
second: Second!
1411+
string: String
1412+
}
1413+
```
13681414

13691415
### Input Object Extensions
13701416

0 commit comments

Comments
 (0)