-
Notifications
You must be signed in to change notification settings - Fork 1.1k
RFC: OneOf Input Objects #825
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
Changes from 20 commits
c385058
f6bd659
39e593c
b6741c3
d17d5ec
dca3826
7e02f5a
4111476
6754e0a
7c4c1a2
bb225f7
05fde06
e8f6145
08abf49
59cb12d
c470afb
99aa5d9
691087d
7109dbc
05ab541
6a6be52
de87d2f
57e2388
5a966f2
e78d2b5
c6cd857
d106233
87d0b22
d88d62a
a810aef
a1563a9
b45c0e4
0c9830e
c4d0b50
340594e
dbccf84
17f1304
d15f7bb
6310475
c26463f
ff986be
016f47f
b1ff1ab
9bec236
59ad4b7
dddd4b8
0f19c3e
128807c
d3e359b
ec85436
47cbe95
2998f7d
5f6e777
fdbe55d
7b8d17f
f34d562
a500eca
d7173d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ words: | |
- tatooine | ||
- zuck | ||
- zuckerberg | ||
- brontie | ||
- oneOf |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,10 @@ type Query { | |
dog: Dog | ||
} | ||
|
||
type Mutation { | ||
addPet(pet: PetInput): Pet | ||
} | ||
|
||
enum DogCommand { | ||
SIT | ||
DOWN | ||
|
@@ -87,6 +91,23 @@ type Cat implements Pet { | |
union CatOrDog = Cat | Dog | ||
union DogOrHuman = Dog | Human | ||
union HumanOrAlien = Human | Alien | ||
|
||
input CatInput { | ||
name: String! | ||
nickname: String | ||
meowVolume: Int | ||
} | ||
|
||
input DogInput { | ||
name: String! | ||
nickname: String | ||
barkVolume: Int | ||
} | ||
|
||
input PetInput @oneOf { | ||
cat: CatInput | ||
dog: DogInput | ||
} | ||
``` | ||
|
||
## Documents | ||
|
@@ -1406,6 +1427,103 @@ arguments, an input object may have required fields. An input field is required | |
if it has a non-null type and does not have a default value. Otherwise, the | ||
input object field is optional. | ||
|
||
### OneOf Input Objects Have Exactly One Field | ||
|
||
**Formal Specification** | ||
|
||
- For each {operation} in {document}: | ||
- Let {oneofInputObjects} be all OneOf Input Objects transitively included in | ||
the {operation}. | ||
- For each {oneofInputObject} in {oneofInputObjects}: | ||
- Let {fields} be the fields provided by {oneofInputObject}. | ||
benjie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- {fields} must contain exactly one entry. | ||
- Let {field} be the sole entry in {fields}. | ||
- Let {value} be the value of {field}. | ||
- {value} must not be the {null} literal. | ||
- If {value} is a variable: | ||
- Let {variableName} be the name of {variable}. | ||
- Let {variableDefinition} be the {VariableDefinition} named | ||
{variableName} defined within {operation}. | ||
- Let {variableType} be the expected type of {variableDefinition}. | ||
- {variableType} must be a non-null type. | ||
|
||
|
||
**Explanatory Text** | ||
|
||
OneOf Input Objects require that exactly one field must be supplied and that | ||
field must not be {null}. | ||
|
||
An empty OneOf Input Object is invalid. | ||
|
||
```graphql counter-example | ||
mutation addPet { | ||
addPet(pet: {}) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
Multiple fields are not allowed. | ||
|
||
```graphql counter-example | ||
mutation addPet($cat: CatInput, $dog: DogInput) { | ||
addPet(pet: { cat: $cat, dog: $dog }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
```graphql counter-example | ||
mutation addPet($dog: DogInput) { | ||
addPet(pet: { cat: { name: "Brontie" }, dog: $dog }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
```graphql counter-example | ||
mutation addPet { | ||
addPet(pet: { cat: { name: "Brontie" }, dog: null }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
Variables used for OneOf Input Object fields must be non-nullable. | ||
|
||
```graphql example | ||
mutation addPet($cat: CatInput!) { | ||
addPet(pet: { cat: $cat }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
```graphql counter-example | ||
mutation addPet($cat: CatInput) { | ||
addPet(pet: { cat: $cat }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
If a field with a literal value is present then the value must not be {null}. | ||
|
||
```graphql example | ||
mutation addPet { | ||
addPet(pet: { cat: { name: "Brontie" } }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
```graphql counter-example | ||
mutation addPet { | ||
addPet(pet: { cat: null }) { | ||
name | ||
} | ||
} | ||
``` | ||
|
||
## Directives | ||
|
||
### Directives Are Defined | ||
|
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.
forever immortalized!