Compatible Values
Formal Specification
- For each argument in the document
- Let value be the Value of argument
- If
value
is not a Variable
- Let argumentName be the Name of argument .
- Let argumentDefinition be the argument definition provided by the parent field or definition named argumentName .
- Let type be the type expected by argumentDefinition .
- The type of literalArgument must be coercible to type .
Explanatory Text
Literal values must be compatible with the type defined by the argument they are being provided to, as per the coercion rules defined in the Type System chapter.
For example, an Int can be coerced into a Float.
fragment goodBooleanArg on Arguments {
booleanArgField(booleanArg: true)
}
fragment coercedIntIntoFloatArg on Arguments {
floatArgField(floatArg: 1)
}
An incoercible conversion, is string to int. Therefore, the following example is invalid.
fragment stringIntoInt on Arguments {
intArgField(intArg: "3")
}