Coercing Field Arguments
Fields may include arguments which are provided to the underlying runtime in order to correctly produce a value. These arguments are defined by the field in the type system to have a specific input type: Scalars, Enum, Input Object, or List or Non‐Null wrapped variations of these three.
At each argument position in a query may be a literal value or a variable to be provided at runtime.
(
objectType
,
field
,
variableValues
)
- Let coercedValues be an empty unordered Map.
- Let argumentValues be the argument values provided in field .
- Let fieldName be the name of field .
- Let argumentDefinitions be the arguments defined by objectType for the field named fieldName .
- For each
argumentDefinition
in
argumentDefinitions
:
- Let argumentName be the name of argumentDefinition .
- Let argumentType be the expected type of argumentDefinition .
- Let defaultValue be the default value for argumentDefinition .
- Let value be the value provided in argumentValues for the name argumentName .
- If
value
is a Variable:
- Let variableName be the name of Variable value .
- Let variableValue be the value provided in variableValues for the name variableName .
- If
variableValue
exists (including
null
):
- Add an entry to coercedValues named argName with the value variableValue .
- Otherwise, if
defaultValue
exists (including
null
):
- Add an entry to coercedValues named argName with the value defaultValue .
- Otherwise, if argumentType is a Non‐Nullable type, throw a field error.
- Otherwise, continue to the next argument definition.
- Otherwise, if
value
does not exist (was not provided in
argumentValues
:
- If
defaultValue
exists (including
null
):
- Add an entry to coercedValues named argName with the value defaultValue .
- Otherwise, if argumentType is a Non‐Nullable type, throw a field error.
- Otherwise, continue to the next argument definition.
- If
defaultValue
exists (including
null
):
- Otherwise, if value cannot be coerced according to the input coercion rules of argType , throw a field error.
- Let coercedValue be the result of coercing value according to the input coercion rules of argType .
- Add an entry to coercedValues named argName with the value coercedValue .
- Return coercedValues .
Variable values are not coerced because they are expected to be coerced before executing the operation in
()
, and valid queries must only allow usage of variables of appropriate types.