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.

CoerceArgumentValues

(

objectType

,

field

,

variableValues

)

  1. Let coercedValues be an empty unordered Map.
  2. Let argumentValues be the argument values provided in field .
  3. Let fieldName be the name of field .
  4. Let argumentDefinitions be the arguments defined by objectType for the field named fieldName .
  5. For each argumentDefinition in argumentDefinitions :
    1. Let argumentName be the name of argumentDefinition .
    2. Let argumentType be the expected type of argumentDefinition .
    3. Let defaultValue be the default value for argumentDefinition .
    4. Let value be the value provided in argumentValues for the name argumentName .
    5. If value is a Variable:
      1. Let variableName be the name of Variable value .
      2. Let variableValue be the value provided in variableValues for the name variableName .
      3. If variableValue exists (including null ):
        1. Add an entry to coercedValues named argName with the value variableValue .
      4. Otherwise, if defaultValue exists (including null ):
        1. Add an entry to coercedValues named argName with the value defaultValue .
      5. Otherwise, if argumentType is a Non‐Nullable type, throw a field error.
      6. Otherwise, continue to the next argument definition.
    6. Otherwise, if value does not exist (was not provided in argumentValues :
      1. If defaultValue exists (including null ):
        1. Add an entry to coercedValues named argName with the value defaultValue .
      2. Otherwise, if argumentType is a Non‐Nullable type, throw a field error.
      3. Otherwise, continue to the next argument definition.
    7. Otherwise, if value cannot be coerced according to the input coercion rules of argType , throw a field error.
    8. Let coercedValue be the result of coercing value according to the input coercion rules of argType .
    9. Add an entry to coercedValues named argName with the value coercedValue .
  6. Return coercedValues .

Variable values are not coerced because they are expected to be coerced before executing the operation in

CoerceVariableValues

()

, and valid queries must only allow usage of variables of appropriate types.

results matching ""

    No results matching ""