-
Notifications
You must be signed in to change notification settings - Fork 1.1k
OneOf inhabitability #1211
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
Open
jbellenger
wants to merge
4
commits into
graphql:main
Choose a base branch
from
jbellenger:jbellenger-oneof-inhabitability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
OneOf inhabitability #1211
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1642,6 +1642,35 @@ input Second { | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| _OneOf Input Objects_ introduce another case where a field cannot be provided a | ||||||||||||||||||||||||||||||
| finite value. Because exactly one field must be set and must be non-null, | ||||||||||||||||||||||||||||||
| nullable fields do not provide an escape from recursion as they do in regular | ||||||||||||||||||||||||||||||
| Input Objects. This OneOf Input Object is invalid because its only field | ||||||||||||||||||||||||||||||
| references itself, and a non-null value must always be provided: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```graphql counter-example | ||||||||||||||||||||||||||||||
| input Example @oneOf { | ||||||||||||||||||||||||||||||
| self: Example | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| However, a OneOf Input Object that references itself is valid when at least one | ||||||||||||||||||||||||||||||
| field provides a path to a type that is not a OneOf Input Object: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```graphql example | ||||||||||||||||||||||||||||||
| input PetInput @oneOf { | ||||||||||||||||||||||||||||||
| cat: CatInput | ||||||||||||||||||||||||||||||
| dog: DogInput | ||||||||||||||||||||||||||||||
| self: PetInput | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| input CatInput { | ||||||||||||||||||||||||||||||
| name: String! | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| input DogInput { | ||||||||||||||||||||||||||||||
| name: String! | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| **Result Coercion** | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| An input object is never a valid result. Input Object types cannot be the return | ||||||||||||||||||||||||||||||
|
|
@@ -1730,6 +1759,8 @@ input ExampleInputObject { | |||||||||||||||||||||||||||||
| Input Objects, at least one of the fields in the chain of references must be | ||||||||||||||||||||||||||||||
| either a nullable or a List type. | ||||||||||||||||||||||||||||||
| 4. {InputObjectDefaultValueHasCycle(inputObject)} must be {false}. | ||||||||||||||||||||||||||||||
| 5. If the Input Object is a _OneOf Input Object_, | ||||||||||||||||||||||||||||||
| {OneOfInputObjectCanBeProvidedAFiniteValue(inputObject)} must be {true}. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| InputObjectDefaultValueHasCycle(inputObject, defaultValue, visitedFields): | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -1768,6 +1799,26 @@ InputFieldDefaultValueHasCycle(field, defaultValue, visitedFields): | |||||||||||||||||||||||||||||
| - Return {InputObjectDefaultValueHasCycle(namedFieldType, fieldDefaultValue, | ||||||||||||||||||||||||||||||
| nextVisitedFields)}. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| OneOfInputObjectCanBeProvidedAFiniteValue(oneOfInputObject, visited): | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| - If {visited} is not provided, initialize it to the empty set. | ||||||||||||||||||||||||||||||
| - If {oneOfInputObject} is within {visited}: | ||||||||||||||||||||||||||||||
| - Return {false}. | ||||||||||||||||||||||||||||||
| - Let {nextVisited} be a new set containing {oneOfInputObject} and everything | ||||||||||||||||||||||||||||||
| from {visited}. | ||||||||||||||||||||||||||||||
| - For each field {field} of {oneOfInputObject}: | ||||||||||||||||||||||||||||||
| - Let {fieldType} be the type of {field}. | ||||||||||||||||||||||||||||||
| - If {fieldType} is a List type: | ||||||||||||||||||||||||||||||
| - Return {true}. | ||||||||||||||||||||||||||||||
| - Let {namedFieldType} be the underlying named type of {fieldType}. | ||||||||||||||||||||||||||||||
| - If {namedFieldType} is not an Input Object type: | ||||||||||||||||||||||||||||||
| - Return {true}. | ||||||||||||||||||||||||||||||
| - If {namedFieldType} is not a _OneOf Input Object_: | ||||||||||||||||||||||||||||||
| - Return {true}. | ||||||||||||||||||||||||||||||
| - If {OneOfInputObjectCanBeProvidedAFiniteValue(namedFieldType, nextVisited)}: | ||||||||||||||||||||||||||||||
| - Return {true}. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| - Let {namedFieldType} be the underlying named type of {fieldType}. | |
| - If {namedFieldType} is not an Input Object type: | |
| - Return {true}. | |
| - If {namedFieldType} is not a _OneOf Input Object_: | |
| - Return {true}. | |
| - If {OneOfInputObjectCanBeProvidedAFiniteValue(namedFieldType, nextVisited)}: | |
| - Return {true}. | |
| - Assert: {fieldType} is a named type. | |
| - If {fieldType} is not an Input Object type: | |
| - Return {true}. | |
| - If {fieldType} is not a _OneOf Input Object_ type: | |
| - Return {true}. | |
| - If {OneOfInputObjectCanBeProvidedAFiniteValue(fieldType, nextVisited)}: | |
| - Return {true}. |
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.