@@ -42,7 +42,8 @@ type Query {
42
42
}
43
43
44
44
type Mutation {
45
- addPet (pet : PetInput ): Pet
45
+ addPet (pet : PetInput ! ): Pet
46
+ addPets (pet : [PetInput ! ]! ): [Pet ]
46
47
}
47
48
48
49
enum DogCommand {
@@ -1355,6 +1356,12 @@ query goodComplexDefaultValue($search: FindDogInput = { name: "Fido" }) {
1355
1356
name
1356
1357
}
1357
1358
}
1359
+
1360
+ mutation addPet ($pet : PetInput ! = { cat : { name : " Brontie" } }) {
1361
+ addPet (pet : $pet ) {
1362
+ name
1363
+ }
1364
+ }
1358
1365
```
1359
1366
1360
1367
Non-coercible values (such as a String into an Int) are invalid. The following
@@ -1370,6 +1377,24 @@ query badComplexValue {
1370
1377
name
1371
1378
}
1372
1379
}
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
+ }
1373
1398
```
1374
1399
1375
1400
### Input Object Field Names
@@ -1456,103 +1481,6 @@ arguments, an input object may have required fields. An input field is required
1456
1481
if it has a non-null type and does not have a default value. Otherwise, the
1457
1482
input object field is optional.
1458
1483
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
-
1556
1484
## Directives
1557
1485
1558
1486
### Directives Are Defined
@@ -1993,8 +1921,8 @@ IsVariableUsageAllowed(variableDefinition, variableUsage):
1993
1921
- Let {variableType} be the expected type of {variableDefinition}.
1994
1922
- Let {locationType} be the expected type of the {Argument}, {ObjectField}, or
1995
1923
{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:
1998
1926
- Let {hasNonNullVariableDefaultValue} be {true} if a default value exists for
1999
1927
{variableDefinition} and is not the value {null}.
2000
1928
- Let {hasLocationDefaultValue} be {true} if a default value exists for the
@@ -2005,6 +1933,15 @@ IsVariableUsageAllowed(variableDefinition, variableUsage):
2005
1933
- Return {AreTypesCompatible(variableType, nullableLocationType)}.
2006
1934
- Return {AreTypesCompatible(variableType, locationType)}.
2007
1935
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
+
2008
1945
AreTypesCompatible(variableType, locationType):
2009
1946
2010
1947
- If {locationType} is a non-null type:
@@ -2093,6 +2030,34 @@ query listToNonNullList($booleanList: [Boolean]) {
2093
2030
This would fail validation because a ` [T] ` cannot be passed to a ` [T]! ` .
2094
2031
Similarly a ` [T] ` cannot be passed to a ` [T!] ` .
2095
2032
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
+
2096
2061
** Allowing Optional Variables When Default Values Exist**
2097
2062
2098
2063
A notable exception to typical variable type compatibility is allowing a
0 commit comments