Skip to content

Commit 7c4c1a2

Browse files
committed
Oneof's now require exactly one field/argument, and non-nullable variables.
1 parent 6754e0a commit 7c4c1a2

File tree

2 files changed

+59
-53
lines changed

2 files changed

+59
-53
lines changed

spec/Section 3 -- Type System.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,13 +1595,20 @@ is constructed with the following rules:
15951595
definition does not provide a default value, the input object field
15961596
definition's default value should be used.
15971597

1598-
* If the input object is a Oneof Input Object:
1598+
Further, if the input object is a Oneof Input Object, the following additional
1599+
rules apply:
15991600

1600-
* If the coerced unordered map does not contain exactly one entry, an error
1601-
must be thrown.
1601+
* If the input object literal or unordered map does not contain exactly one
1602+
entry, an error must be thrown.
16021603

1603-
* If the value of the single entry in the coerced unordered map is {null}, an
1604-
error must be thrown.
1604+
* If the single entry in the input object literal or unordered map is {null},
1605+
an error must be thrown.
1606+
1607+
* If the coerced unordered map does not contain exactly one entry, an error
1608+
must be thrown.
1609+
1610+
* If the value of the single entry in the coerced unordered map is {null}, an
1611+
error must be thrown.
16051612

16061613
Following are examples of input coercion for an input object type with a
16071614
`String` field `a` and a required (non-null) `Int!` field `b`:
@@ -1649,24 +1656,20 @@ Literal Value | Variables | Coerced Value
16491656
`{ a: null, b: 123 }` | `{}` | Error: Exactly one key must be specified
16501657
`{ b: 123 }` | `{}` | `{ b: 123 }`
16511658
`{ a: $var, b: 123 }` | `{ var: null }` | Error: Exactly one key must be specified
1652-
`{ a: $var, b: 123 }` | `{}` | `{ b: 123 }`
1659+
`{ a: $var, b: 123 }` | `{}` | Error: Exactly one key must be specified
16531660
`{ b: $var }` | `{ var: 123 }` | `{ b: 123 }`
16541661
`$var` | `{ var: { b: 123 } }` | `{ b: 123 }`
16551662
`"abc123"` | `{}` | Error: Incorrect value
16561663
`$var` | `{ var: "abc123" } }` | Error: Incorrect value
16571664
`{ a: "abc", b: "123" }` | `{}` | Error: Exactly one key must be specified
16581665
`{ b: "123" }` | `{}` | Error: Incorrect value for member field {b}
16591666
`{ a: "abc" }` | `{}` | `{ a: "abc" }`
1660-
`{ b: $var }` | `{}` | Error: No keys were specified
1667+
`{ b: $var }` | `{}` | Error: Exactly one key must be specified
16611668
`$var` | `{ var: { a: "abc" } }` | `{ a: "abc" }`
16621669
`{ a: "abc", b: null }` | `{}` | Error: Exactly one key must be specified
16631670
`{ b: $var }` | `{ var: null }` | Error: Value for member field {b} must be non-null
16641671
`{ b: 123, c: "xyz" }` | `{}` | Error: Exactly one key must be specified
1665-
`{ a: $a, b: $b }` | `{}` | Error: Exactly one key must be specified
1666-
`{ a: $a, b: $b }` | `{ a: "abc" }` | `{ a: "abc" }`
1667-
`{ a: $a, b: $b }` | `{ b: 123 }` | `{ b: 123 }`
1668-
`{ a: $a, b: $b }` | `{ a: "abc", b: 123 }` | Error: Exactly one key must be specified
1669-
`{ a: $a, b: $b }` | `{ a: null, b: 123 }` | Error: Exactly one key must be specified
1672+
`{ a: $a, b: $b }` | `{ a: "abc" }` | Error: Exactly one key must be specified
16701673

16711674
**Type Validation**
16721675

spec/Section 5 -- Validation.md

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,19 @@ fragment missingRequiredArg on Arguments {
803803

804804
#### Oneof Fields Have Exactly One Argument
805805

806-
* For each Oneof Field in the document:
807-
* Let {arguments} be the arguments provided by the Field.
808-
* {arguments} must contain exactly one entry.
809-
* For the sole {argument} in {arguments}:
806+
* For each {operation} in {document}:
807+
* Let {oneofFields} be all Oneof Fields transitively included in the {operation}.
808+
* For each {oneofField} in {oneofFields}:
809+
* Let {arguments} be the arguments provided by {oneofField}.
810+
* {arguments} must contain exactly one entry.
811+
* Let {argument} be the sole entry in {arguments}.
810812
* Let {value} be the value of {argument}.
811813
* {value} must not be the {null} literal.
814+
* If {value} is a variable:
815+
* Let {variableName} be the name of {variable}.
816+
* Let {variableDefinition} be the {VariableDefinition} named {variableName} defined within {operation}.
817+
* Let {variableType} be the expected type of {variableDefinition}.
818+
* {variableType} must be a non-null type.
812819

813820
**Explanatory Text**
814821

@@ -1467,23 +1474,15 @@ input object field is optional.
14671474
* Let {oneofInputObjects} be all Oneof Input Objects transitively included in the {operation}.
14681475
* For each {oneofInputObject} in {oneofInputObjects}:
14691476
* Let {fields} be the fields provided by {oneofInputObject}.
1470-
* {fields} must not be empty.
1471-
* Let {literalFields} be the entries in {fields} that have literal values.
1472-
* If {literalFields} is not empty:
1473-
* {literalFields} must contain exactly one entry.
1474-
* {fields} must contain exactly one entry.
1475-
* For the sole {field} in {literalFields}:
1476-
* Let {value} be the value of {field}.
1477-
* {value} must not be the {null} literal.
1478-
* Otherwise:
1479-
* Let {variableUsages} be all variable usages within {oneofInputObject} directly.
1480-
* Assert: {variableUsages} is not empty.
1481-
* For each {variableUsage} in {variableUsages}:
1482-
* Let {variableName} be the name of {variableUsage}.
1483-
* Let {variableDefinition} be the {VariableDefinition} named {variableName} defined within {operation}.
1484-
* Let {variableType} be the expected type of {variableDefinition}.
1485-
* If {variableType} is a non-null type:
1486-
* {fields} must contain exactly one entry.
1477+
* {fields} must contain exactly one entry.
1478+
* Let {field} be the sole entry in {fields}.
1479+
* Let {value} be the value of {field}.
1480+
* {value} must not be the {null} literal.
1481+
* If {value} is a variable:
1482+
* Let {variableName} be the name of {variable}.
1483+
* Let {variableDefinition} be the {VariableDefinition} named {variableName} defined within {operation}.
1484+
* Let {variableType} be the expected type of {variableDefinition}.
1485+
* {variableType} must be a non-null type.
14871486

14881487
**Explanatory Text**
14891488

@@ -1500,20 +1499,34 @@ query addPet {
15001499
}
15011500
```
15021501

1503-
Multiple fields of a Oneof Input Object may be specified via variables (at most
1504-
one of which may be provided at run time), thus we allow multiple variable
1505-
fields.
1502+
Multiple fields are not allowed.
15061503

1507-
```graphgl example
1504+
```graphgl counter-example
15081505
query addPet($cat: CatInput, $dog: DogInput) {
15091506
addPet(pet: {cat: $cat, dog: $dog}) {
15101507
name
15111508
}
15121509
}
15131510
```
15141511

1515-
If a field of a Oneof Input Object is specified via a non-nullable variable, no
1516-
other fields may be specified:
1512+
```graphgl counter-example
1513+
query addPet($dog: DogInput) {
1514+
addPet(pet: { cat: { name: "Brontie" }, dog: $dog }) {
1515+
name
1516+
}
1517+
}
1518+
```
1519+
1520+
```graphgl counter-example
1521+
query addPet {
1522+
addPet(pet: { cat: { name: "Brontie" }, dog: null }) {
1523+
name
1524+
}
1525+
}
1526+
```
1527+
1528+
1529+
Variables used for Oneof Input Object fields must be non-nullable.
15171530

15181531
```graphgl example
15191532
query addPet($cat: CatInput!) {
@@ -1524,15 +1537,16 @@ query addPet($cat: CatInput!) {
15241537
```
15251538

15261539
```graphgl counter-example
1527-
query addPet($cat: CatInput!, $dog: DogInput) {
1528-
addPet(pet: { cat: $cat, dog: $dog }) {
1540+
query addPet($cat: CatInput) {
1541+
addPet(pet: { cat: $cat }) {
15291542
name
15301543
}
15311544
}
15321545
```
15331546

1547+
15341548
If a field with a literal value is present then the value must
1535-
not be {null} and no fields with variable values are allowed.
1549+
not be {null}.
15361550

15371551
```graphgl example
15381552
query addPet {
@@ -1550,17 +1564,6 @@ query addPet {
15501564
}
15511565
```
15521566

1553-
```graphgl counter-example
1554-
query addPet($dog: DogInput) {
1555-
addPet(pet: { cat: { name: "Brontie" }, dog: $dog }) {
1556-
name
1557-
}
1558-
}
1559-
```
1560-
1561-
Note: When the fields of a Oneof Input Object are supplied via variables, we
1562-
assert that the input object has exactly one field during coercion.
1563-
15641567

15651568
## Directives
15661569

0 commit comments

Comments
 (0)