Skip to content

Disallow non-breakable chains of circular references in Input Objects #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,60 @@ define arguments or contain references to interfaces and unions, neither of
which is appropriate for use as an input argument. For this reason, input
objects have a separate type in the system.

**Circular References**

Input Objects are allowed to reference other Input Objects as field types. A
circular reference occurs when an Input Object references itself either directly
or through referenced Input Objects.

Circular references are generally allowed, however they may not be defined as an
unbroken chain of Non-Null singular fields. Such Input Objects are invalid
because there is no way to provide a legal value for them.

This example of a circularly-referenced input type is valid as the field `self`
may be omitted or the value {null}.

```graphql example
input Example {
self: Example
value: String
}
```

This example is also valid as the field `self` may be an empty List.

```graphql example
input Example {
self: [Example!]!
value: String
}
```

This example of a circularly-referenced input type is invalid as the field
`self` cannot be provided a finite value.

```graphql counter-example
input Example {
value: String
self: Example!
}
```

This example is also invalid, as there is a non-null singular circular reference
via the `First.second` and `Second.first` fields.

```graphql counter-example
input First {
second: Second!
value: String
}

input Second {
first: First!
value: String
}
```

**Result Coercion**

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


### Input Object Extensions
Expand Down