@@ -1452,103 +1452,6 @@ arguments, an input object may have required fields. An input field is required
14521452if it has a non-null type and does not have a default value. Otherwise, the
14531453input object field is optional.
14541454
1455- ### OneOf Input Objects Have Exactly One Field
1456-
1457- ** Formal Specification**
1458-
1459- - For each {operation} in {document}:
1460- - Let {oneofInputObjects} be all OneOf Input Objects transitively included in
1461- the {operation}.
1462- - For each {oneofInputObject} in {oneofInputObjects}:
1463- - Let {fields} be the fields provided by {oneofInputObject}.
1464- - {fields} must contain exactly one entry.
1465- - Let {field} be the sole entry in {fields}.
1466- - Let {value} be the value of {field}.
1467- - {value} must not be the {null} literal.
1468- - If {value} is a variable:
1469- - Let {variableName} be the name of {variable}.
1470- - Let {variableDefinition} be the {VariableDefinition} named
1471- {variableName} defined within {operation}.
1472- - Let {variableType} be the expected type of {variableDefinition}.
1473- - {variableType} must be a non-null type.
1474-
1475- ** Explanatory Text**
1476-
1477- OneOf Input Objects require that exactly one field must be supplied and that
1478- field must not be {null}.
1479-
1480- An empty OneOf Input Object is invalid.
1481-
1482- ``` graphql counter-example
1483- mutation addPet {
1484- addPet (pet : {}) {
1485- name
1486- }
1487- }
1488- ```
1489-
1490- Multiple fields are not allowed.
1491-
1492- ``` graphql counter-example
1493- mutation addPet ($cat : CatInput , $dog : DogInput ) {
1494- addPet (pet : { cat : $cat , dog : $dog }) {
1495- name
1496- }
1497- }
1498- ```
1499-
1500- ``` graphql counter-example
1501- mutation addPet ($dog : DogInput ) {
1502- addPet (pet : { cat : { name : " Brontie" }, dog : $dog }) {
1503- name
1504- }
1505- }
1506- ```
1507-
1508- ``` graphql counter-example
1509- mutation addPet {
1510- addPet (pet : { cat : { name : " Brontie" }, dog : null }) {
1511- name
1512- }
1513- }
1514- ```
1515-
1516- Variables used for OneOf Input Object fields must be non-nullable.
1517-
1518- ``` graphql example
1519- mutation addPet ($cat : CatInput ! ) {
1520- addPet (pet : { cat : $cat }) {
1521- name
1522- }
1523- }
1524- ```
1525-
1526- ``` graphql counter-example
1527- mutation addPet ($cat : CatInput ) {
1528- addPet (pet : { cat : $cat }) {
1529- name
1530- }
1531- }
1532- ```
1533-
1534- If a field with a literal value is present then the value must not be {null}.
1535-
1536- ``` graphql example
1537- mutation addPet {
1538- addPet (pet : { cat : { name : " Brontie" } }) {
1539- name
1540- }
1541- }
1542- ```
1543-
1544- ``` graphql counter-example
1545- mutation addPet {
1546- addPet (pet : { cat : null }) {
1547- name
1548- }
1549- }
1550- ```
1551-
15521455## Directives
15531456
15541457### Directives Are Defined
@@ -1989,8 +1892,8 @@ IsVariableUsageAllowed(variableDefinition, variableUsage):
19891892- Let {variableType} be the expected type of {variableDefinition}.
19901893- Let {locationType} be the expected type of the {Argument}, {ObjectField}, or
19911894 {ListValue} entry where {variableUsage} is located.
1992- - If {locationType} is a non-null type AND {variableType} is NOT a non-null
1993- type:
1895+ - If {IsNonNullPosition( locationType, variableUsage)} AND {variableType} is NOT
1896+ a non-null type:
19941897 - Let {hasNonNullVariableDefaultValue} be {true} if a default value exists for
19951898 {variableDefinition} and is not the value {null}.
19961899 - Let {hasLocationDefaultValue} be {true} if a default value exists for the
@@ -2001,6 +1904,15 @@ IsVariableUsageAllowed(variableDefinition, variableUsage):
20011904 - Return {AreTypesCompatible(variableType, nullableLocationType)}.
20021905- Return {AreTypesCompatible(variableType, locationType)}.
20031906
1907+ IsNonNullPosition(locationType, variableUsage):
1908+
1909+ - Let {isOneOfField} be {true} if {variableUsage} is located within an
1910+ {ObjectField} entry and the parent type of {ObjectField} is a OneOf Input
1911+ Object; otherwise {false}.
1912+ - If {isOneOfField} is {true} or {locationType} is a non-null type, return
1913+ {true}.
1914+ - Return {false}.
1915+
20041916AreTypesCompatible(variableType, locationType):
20051917
20061918- If {locationType} is a non-null type:
@@ -2089,6 +2001,34 @@ query listToNonNullList($booleanList: [Boolean]) {
20892001This would fail validation because a ` [T] ` cannot be passed to a ` [T]! ` .
20902002Similarly a ` [T] ` cannot be passed to a ` [T!] ` .
20912003
2004+ Variables used for OneOf Input Object fields must be non-nullable.
2005+
2006+ ``` graphql example
2007+ mutation addPet ($cat : CatInput ! ) {
2008+ addPet (pet : { cat : $cat }) {
2009+ name
2010+ }
2011+ }
2012+ ```
2013+
2014+ ``` graphql counter-example
2015+ mutation addPet ($cat : CatInput ) {
2016+ addPet (pet : { cat : $cat }) {
2017+ name
2018+ }
2019+ }
2020+ ```
2021+
2022+ Variables used for OneOf Input Object fields cannot have default values.
2023+
2024+ ``` graphql counter-example
2025+ mutation addPet ($cat : CatInput = { name : " Kitty" }) {
2026+ addPet (pet : { cat : $cat }) {
2027+ name
2028+ }
2029+ }
2030+ ```
2031+
20922032** Allowing Optional Variables When Default Values Exist**
20932033
20942034A notable exception to typical variable type compatibility is allowing a
0 commit comments