@@ -1448,6 +1448,28 @@ define arguments or contain references to interfaces and unions, neither of
14481448which is appropriate for use as an input argument . For this reason , input
14491449objects have a separate type in the system .
14501450
1451+ **Oneof Input Objects **
1452+
1453+ Oneof Input Objects are a special variant of Input Objects where the type
1454+ system asserts that exactly one of the fields must be set and non -null , all
1455+ others being omitted . This is useful for representing situations where an input
1456+ may be one of many different options .
1457+
1458+ When using the type system definition language , the `@oneOf ` directive is used
1459+ to indicate that an Input Object is a Oneof Input Object (and thus requires
1460+ exactly one of its field be provided):
1461+
1462+ ```graphql
1463+ input UserUniqueCondition @oneOf {
1464+ id : ID
1465+ username : String
1466+ organizationAndEmail : OrganizationAndEmailInput
1467+ }
1468+ ```
1469+
1470+ In schema introspection, the `__Type.oneField` field will return {true} for
1471+ Oneof Input Objects , and {false } for all other Input Objects .
1472+
14511473**Circular References **
14521474
14531475Input Objects are allowed to reference other Input Objects as field types . A
@@ -1570,6 +1592,37 @@ Literal Value | Variables | Coerced Value
15701592`{ b : $var }` | `{ var : null }` | Error : {b } must be non -null .
15711593`{ b : 123, c : "xyz" }` | `{}` | Error : Unexpected field {c }
15721594
1595+
1596+ Following are examples of input coercion for a Oneof Input Object with a
1597+ `String ` member field `a ` and an `Int ` member field `b `:
1598+
1599+ ```graphql example
1600+ input ExampleInputTagged @oneOf {
1601+ a : String
1602+ b : Int
1603+ }
1604+ ```
1605+
1606+ Literal Value | Variables | Coerced Value
1607+ ------------------------ | ----------------------- | ---------------------------
1608+ `{ a : "abc" , b : 123 }` | `{}` | Error : Exactly one key must be specified
1609+ `{ a : null , b : 123 }` | `{}` | Error : Exactly one key must be specified
1610+ `{ b : 123 }` | `{}` | `{ b : 123 }`
1611+ `{ a : $var , b : 123 }` | `{ var : null }` | Error : Exactly one key must be specified
1612+ `{ a : $var , b : 123 }` | `{}` | `{ b : 123 }`
1613+ `{ b : $var }` | `{ var : 123 }` | `{ b : 123 }`
1614+ `$var ` | `{ var : { b : 123 } }` | `{ b : 123 }`
1615+ `"abc123" ` | `{}` | Error : Incorrect value
1616+ `$var ` | `{ var : "abc123" } }` | Error : Incorrect value
1617+ `{ a : "abc" , b : "123" }` | `{}` | Error : Exactly one key must be specified
1618+ `{ b : "123" }` | `{}` | Error : Incorrect value for member field {b }
1619+ `{ a : "abc" }` | `{}` | `{ a : "abc" }`
1620+ `{ b : $var }` | `{}` | Error : No keys were specified
1621+ `$var ` | `{ var : { a : "abc" } }` | `{ a : "abc" }`
1622+ `{ a : "abc" , b : null }` | `{}` | Error : Exactly one key must be specified
1623+ `{ b : $var }` | `{ var : null }` | Error : Value for member field {b } must be non -null
1624+ `{ b : 123, c : "xyz" }` | `{}` | Error : Exactly one key must be specified
1625+
15731626**Type Validation **
15741627
157516281. An Input Object type must define one or more input fields .
@@ -1580,6 +1633,9 @@ Literal Value | Variables | Coerced Value
15801633 characters {"__" } (two underscores).
15811634 3. The input field must accept a type where {IsInputType (inputFieldType)}
15821635 returns {true }.
1636+ 4. If the Input Object is a Oneof Input Object then :
1637+ 1. The type of the input field must be nullable .
1638+ 2. The input field must not have a default value .
158316393. If an Input Object references itself either directly or through referenced
15841640 Input Objects , at least one of the fields in the chain of references must be
15851641 either a nullable or a List type .
@@ -1605,6 +1661,10 @@ Input object type extensions have the potential to be invalid if incorrectly def
16051661 the original Input Object .
160616624. Any non -repeatable directives provided must not already apply to the
16071663 original Input Object type .
1664+ 5. If the original Input Object is a Oneof Input Object then :
1665+ 1. All fields of the Input Object type extension must be nullable .
1666+ 2. All fields of the Input Object type extension must not have default
1667+ values .
16081668
16091669
16101670## List
@@ -1815,8 +1875,12 @@ by a validator, executor, or client tool such as a code generator.
18151875GraphQL implementations should provide the ` @skip ` and ` @include ` directives.
18161876
18171877GraphQL implementations that support the type system definition language must
1818- provide the ` @deprecated ` directive if representing deprecated portions of
1819- the schema.
1878+ provide:
1879+
1880+ - the ` @deprecated ` directive if representing deprecated portions of the
1881+ schema;
1882+ - the ` @oneOf ` directive if representing types that require exactly one field
1883+ (i.e. Oneof Input Objects).
18201884
18211885** Custom Directives**
18221886
@@ -1980,3 +2044,20 @@ type ExampleType {
19802044 oldField : String @deprecated (reason : "Use `newField`." )
19812045}
19822046```
2047+
2048+ ### @oneOf
2049+
2050+ ``` graphql
2051+ directive @oneOf on INPUT_OBJECT
2052+ ```
2053+
2054+ The `@oneOf ` directive is used within the type system definition language
2055+ to indicate an Input Object is a Oneof Input Object .
2056+
2057+ ```graphql example
2058+ input UserUniqueCondition @oneOf {
2059+ id : ID
2060+ username : String
2061+ organizationAndEmail : OrganizationAndEmailInput
2062+ }
2063+ ```
0 commit comments