Coercing Variable Values

If the operation has defined any variables, then the values for those variables need to be coerced using the input coercion rules of variable’s declared type. If a query error is encountered during input coercion of variable values, then the operation fails without execution.

CoerceVariableValues

(

schema

,

operation

,

variableValues

)

  1. Let coercedValues be an empty unordered Map.
  2. Let variableDefinitions be the variables defined by operation .
  3. For each variableDefinition in variableDefinitions :
    1. Let variableName be the name of variableDefinition .
    2. Let variableType be the expected type of variableDefinition .
    3. Let defaultValue be the default value for variableDefinition .
    4. Let value be the value provided in variableValues for the name variableName .
    5. If value does not exist (was not provided in variableValues ):
      1. If defaultValue exists (including null ):
        1. Add an entry to coercedValues named variableName with the value defaultValue .
      2. Otherwise if variableType is a Non‐Nullable type, throw a query error.
      3. Otherwise, continue to the next variable definition.
    6. Otherwise, if value cannot be coerced according to the input coercion rules of variableType , throw a query error.
    7. Let coercedValue be the result of coercing value according to the input coercion rules of variableType .
    8. Add an entry to coercedValues named variableName with the value coercedValue .
  4. Return coercedValues .

This algorithm is very similar to

CoerceArgumentValues

()

.

results matching ""

    No results matching ""