@@ -42,7 +42,8 @@ type Query {
4242}
4343
4444type Mutation {
45- addPet (pet : PetInput ): Pet
45+ addPet (pet : PetInput ! ): Pet
46+ addPets (pet : [PetInput ! ]! ): [Pet ]
4647}
4748
4849enum DogCommand {
@@ -1355,6 +1356,12 @@ query goodComplexDefaultValue($search: FindDogInput = { name: "Fido" }) {
13551356 name
13561357 }
13571358}
1359+
1360+ mutation addPet ($pet : PetInput ! = { cat : { name : " Brontie" } }) {
1361+ addPet (pet : $pet ) {
1362+ name
1363+ }
1364+ }
13581365```
13591366
13601367Non-coercible values (such as a String into an Int) are invalid. The following
@@ -1370,6 +1377,24 @@ query badComplexValue {
13701377 name
13711378 }
13721379}
1380+
1381+ mutation oneOfWithNoFields {
1382+ addPet (pet : {}) {
1383+ name
1384+ }
1385+ }
1386+
1387+ mutation oneOfWithTwoFields ($dog : DogInput ) {
1388+ addPet (pet : { cat : { name : " Brontie" }, dog : $dog }) {
1389+ name
1390+ }
1391+ }
1392+
1393+ mutation listOfOneOfWithNullableVariable ($dog : DogInput ) {
1394+ addPets (pets : [{ dog : $dog }]) {
1395+ name
1396+ }
1397+ }
13731398```
13741399
13751400### Input Object Field Names
@@ -1456,103 +1481,6 @@ arguments, an input object may have required fields. An input field is required
14561481if it has a non-null type and does not have a default value. Otherwise, the
14571482input object field is optional.
14581483
1459- ### OneOf Input Objects Have Exactly One Field
1460-
1461- ** Formal Specification**
1462-
1463- - For each {operation} in {document}:
1464- - Let {oneofInputObjects} be all OneOf Input Objects transitively included in
1465- the {operation}.
1466- - For each {oneofInputObject} in {oneofInputObjects}:
1467- - Let {fields} be the fields provided by {oneofInputObject}.
1468- - {fields} must contain exactly one entry.
1469- - Let {field} be the sole entry in {fields}.
1470- - Let {value} be the value of {field}.
1471- - {value} must not be the {null} literal.
1472- - If {value} is a variable:
1473- - Let {variableName} be the name of {variable}.
1474- - Let {variableDefinition} be the {VariableDefinition} named
1475- {variableName} defined within {operation}.
1476- - Let {variableType} be the expected type of {variableDefinition}.
1477- - {variableType} must be a non-null type.
1478-
1479- ** Explanatory Text**
1480-
1481- OneOf Input Objects require that exactly one field must be supplied and that
1482- field must not be {null}.
1483-
1484- An empty OneOf Input Object is invalid.
1485-
1486- ``` graphql counter-example
1487- mutation addPet {
1488- addPet (pet : {}) {
1489- name
1490- }
1491- }
1492- ```
1493-
1494- Multiple fields are not allowed.
1495-
1496- ``` graphql counter-example
1497- mutation addPet ($cat : CatInput , $dog : DogInput ) {
1498- addPet (pet : { cat : $cat , dog : $dog }) {
1499- name
1500- }
1501- }
1502- ```
1503-
1504- ``` graphql counter-example
1505- mutation addPet ($dog : DogInput ) {
1506- addPet (pet : { cat : { name : " Brontie" }, dog : $dog }) {
1507- name
1508- }
1509- }
1510- ```
1511-
1512- ``` graphql counter-example
1513- mutation addPet {
1514- addPet (pet : { cat : { name : " Brontie" }, dog : null }) {
1515- name
1516- }
1517- }
1518- ```
1519-
1520- Variables used for OneOf Input Object fields must be non-nullable.
1521-
1522- ``` graphql example
1523- mutation addPet ($cat : CatInput ! ) {
1524- addPet (pet : { cat : $cat }) {
1525- name
1526- }
1527- }
1528- ```
1529-
1530- ``` graphql counter-example
1531- mutation addPet ($cat : CatInput ) {
1532- addPet (pet : { cat : $cat }) {
1533- name
1534- }
1535- }
1536- ```
1537-
1538- If a field with a literal value is present then the value must not be {null}.
1539-
1540- ``` graphql example
1541- mutation addPet {
1542- addPet (pet : { cat : { name : " Brontie" } }) {
1543- name
1544- }
1545- }
1546- ```
1547-
1548- ``` graphql counter-example
1549- mutation addPet {
1550- addPet (pet : { cat : null }) {
1551- name
1552- }
1553- }
1554- ```
1555-
15561484## Directives
15571485
15581486### Directives Are Defined
@@ -1993,8 +1921,8 @@ IsVariableUsageAllowed(variableDefinition, variableUsage):
19931921- Let {variableType} be the expected type of {variableDefinition}.
19941922- Let {locationType} be the expected type of the {Argument}, {ObjectField}, or
19951923 {ListValue} entry where {variableUsage} is located.
1996- - If {locationType} is a non-null type AND {variableType} is NOT a non-null
1997- type:
1924+ - If {IsNonNullPosition( locationType, variableUsage)} AND {variableType} is NOT
1925+ a non-null type:
19981926 - Let {hasNonNullVariableDefaultValue} be {true} if a default value exists for
19991927 {variableDefinition} and is not the value {null}.
20001928 - Let {hasLocationDefaultValue} be {true} if a default value exists for the
@@ -2005,6 +1933,15 @@ IsVariableUsageAllowed(variableDefinition, variableUsage):
20051933 - Return {AreTypesCompatible(variableType, nullableLocationType)}.
20061934- Return {AreTypesCompatible(variableType, locationType)}.
20071935
1936+ IsNonNullPosition(locationType, variableUsage):
1937+
1938+ - If {locationType} is a non-null type, return {true}.
1939+ - If the location of {variableUsage} is an {ObjectField}:
1940+ - Let {parentLocationType} be the expected type of {ObjectField}'s parent
1941+ {ObjectValue}.
1942+ - If {parentLocationType} is a OneOf Input Object type, return {true}.
1943+ - Return {false}.
1944+
20081945AreTypesCompatible(variableType, locationType):
20091946
20101947- If {locationType} is a non-null type:
@@ -2093,6 +2030,34 @@ query listToNonNullList($booleanList: [Boolean]) {
20932030This would fail validation because a ` [T] ` cannot be passed to a ` [T]! ` .
20942031Similarly a ` [T] ` cannot be passed to a ` [T!] ` .
20952032
2033+ Variables used for OneOf Input Object fields must be non-nullable.
2034+
2035+ ``` graphql example
2036+ mutation addCat ($cat : CatInput ! ) {
2037+ addPet (pet : { cat : $cat }) {
2038+ name
2039+ }
2040+ }
2041+ mutation addCatWithDefault ($cat : CatInput ! = { name : " Brontie" }) {
2042+ addPet (pet : { cat : $cat }) {
2043+ name
2044+ }
2045+ }
2046+ ```
2047+
2048+ ``` graphql counter-example
2049+ mutation addNullableCat ($cat : CatInput ) {
2050+ addPet (pet : { cat : $cat }) {
2051+ name
2052+ }
2053+ }
2054+ mutation addNullableCatWithDefault ($cat : CatInput = { name : " Brontie" }) {
2055+ addPet (pet : { cat : $cat }) {
2056+ name
2057+ }
2058+ }
2059+ ```
2060+
20962061** Allowing Optional Variables When Default Values Exist**
20972062
20982063A notable exception to typical variable type compatibility is allowing a
0 commit comments