Variables Are Input Types
Formal Specification
- For every operation in a document
- For every
variable
on each
operation
- Let variableType be the type of variable
- While
variableType
is
LIST
or
NON_NULL
- Let variableType be the referenced type of variableType
- variableType must be of kind SCALAR , ENUM or INPUT_OBJECT
Explanatory Text
Variables can only be scalars, enums, input objects, or lists and non‐null variants of those types. These are known as input types. Objects, unions, and interfaces cannot be used as inputs.
For these examples, consider the following typesystem additions:
input ComplexInput { name: String, owner: String }
extend type QueryRoot {
findDog(complex: ComplexInput): Dog
booleanList(booleanListArg: [Boolean!]): Boolean
}
The following queries are valid:
query takesBoolean($atOtherHomes: Boolean) {
dog {
isHousetrained(atOtherHomes: $atOtherHomes)
}
}
query takesComplexInput($complexInput: ComplexInput) {
findDog(complex: $complexInput) {
name
}
}
query TakesListOfBooleanBang($booleans: [Boolean!]) {
booleanList(booleanListArg: $booleans)
}
The following queries are invalid:
query takesCat($cat: Cat) {
# ...
}
query takesDogBang($dog: Dog!) {
# ...
}
query takesListOfPet($pets: [Pet]) {
# ...
}
query takesCatOrDog($catOrDog: CatOrDog) {
# ...
}