@@ -40,6 +40,10 @@ type Query {
40
40
dog : Dog
41
41
}
42
42
43
+ type Mutation {
44
+ addPet (pet : PetInput ): Pet
45
+ }
46
+
43
47
enum DogCommand { SIT , DOWN , HEEL }
44
48
45
49
type Dog implements Pet {
@@ -81,6 +85,23 @@ type Cat implements Pet {
81
85
union CatOrDog = Cat | Dog
82
86
union DogOrHuman = Dog | Human
83
87
union HumanOrAlien = Human | Alien
88
+
89
+ input CatInput {
90
+ name : String !
91
+ nickname : String
92
+ meowVolume : Int
93
+ }
94
+
95
+ input DogInput {
96
+ name : String !
97
+ nickname : String
98
+ barkVolume : Int
99
+ }
100
+
101
+ input PetInput @oneOf {
102
+ cat : CatInput
103
+ dog : DogInput
104
+ }
84
105
```
85
106
86
107
@@ -1442,17 +1463,103 @@ input object field is optional.
1442
1463
1443
1464
** Formal Specification**
1444
1465
1445
- * For each Oneof Input Object in the document:
1446
- * Let {fields} be the fields provided by that Oneof Input Object.
1447
- * {fields} must contain exactly one entry.
1448
- * For the sole {field} in {fields}:
1449
- * Let {value} be the value of {field}.
1450
- * {value} must not be the {null} literal.
1466
+ * For each {operation} in {document}:
1467
+ * Let {oneofInputObjects} be all Oneof Input Objects transitively included in the {operation}.
1468
+ * For each {oneofInputObject} in {oneofInputObjects}:
1469
+ * 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.
1451
1487
1452
1488
** Explanatory Text**
1453
1489
1454
1490
Oneof Input Objects require that exactly one field must be supplied and that
1455
- field must not be null.
1491
+ field must not be {null}.
1492
+
1493
+ An empty Oneof Input Object is invalid.
1494
+
1495
+ ``` graphgl counter-example
1496
+ query addPet {
1497
+ addPet(pet: {}) {
1498
+ name
1499
+ }
1500
+ }
1501
+ ```
1502
+
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.
1506
+
1507
+ ``` graphgl example
1508
+ query addPet($cat: CatInput, $dog: DogInput) {
1509
+ addPet(pet: {cat: $cat, dog: $dog}) {
1510
+ name
1511
+ }
1512
+ }
1513
+ ```
1514
+
1515
+ If a field of a Oneof Input Object is specified via a non-nullable variable, no
1516
+ other fields may be specified:
1517
+
1518
+ ``` graphgl example
1519
+ query addPet($cat: CatInput!) {
1520
+ addPet(pet: { cat: $cat }) {
1521
+ name
1522
+ }
1523
+ }
1524
+ ```
1525
+
1526
+ ``` graphgl counter-example
1527
+ query addPet($cat: CatInput!, $dog: DogInput) {
1528
+ addPet(pet: { cat: $cat, dog: $dog }) {
1529
+ name
1530
+ }
1531
+ }
1532
+ ```
1533
+
1534
+ 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.
1536
+
1537
+ ``` graphgl example
1538
+ query addPet {
1539
+ addPet(pet: { cat: { name: "Brontie" } }) {
1540
+ name
1541
+ }
1542
+ }
1543
+ ```
1544
+
1545
+ ``` graphgl counter-example
1546
+ query addPet {
1547
+ addPet(pet: { cat: null }) {
1548
+ name
1549
+ }
1550
+ }
1551
+ ```
1552
+
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.
1456
1563
1457
1564
1458
1565
## Directives
0 commit comments