Value Completion

After resolving the value for a field, it is completed by ensuring it adheres to the expected return type. If the return type is another Object type, then the field execution process continues recursively.

CompleteValue

(

fieldType

,

fields

,

result

,

variableValues

)

  1. If the fieldType is a Non‐Null type:
    1. Let innerType be the inner type of fieldType .
    2. Let completedResult be the result of calling CompleteValue ( innerType , fields , result , variableValues ) .
    3. If completedResult is null , throw a field error.
    4. Return completedResult .
  2. If result is null (or another internal value similar to null such as undefined or NaN ), return null .
  3. If fieldType is a List type:
    1. If result is not a collection of values, throw a field error.
    2. Let innerType be the inner type of fieldType .
    3. Return a list where each list item is the result of calling CompleteValue ( innerType , fields , resultItem , variableValues ) , where resultItem is each item in result .
  4. If fieldType is a Scalar or Enum type:
    1. Return the result of “coercing” result , ensuring it is a legal value of fieldType , otherwise null .
  5. If fieldType is an Object, Interface, or Union type:
    1. If fieldType is an Object type.
      1. Let objectType be fieldType .
    2. Otherwise if fieldType is an Interface or Union type.
      1. Let objectType be ResolveAbstractType( fieldType , result ).
    3. Let subSelectionSet be the result of calling MergeSelectionSets ( fields ) .
    4. Return the result of evaluating ExecuteSelectionSet(subSelectionSet, objectType, result, variableValues) normally (allowing for parallelization).

Resolving Abstract Types

When completing a field with an abstract return type, that is an Interface or Union return type, first the abstract type must be resolved to a relevant Object type. This determination is made by the internal system using whatever means appropriate.

A common method of determining the Object type for an

objectValue

in object‐oriented environments, such as Java or C#, is to use the class name of the

objectValue

.

ResolveAbstractType

(

abstractType

,

objectValue

)

  1. Return the result of calling the internal method provided by the type system for determining the Object type of abstractType given the value objectValue .

Merging Selection Sets

When more than one fields of the same name are executed in parallel, their selection sets are merged together when completing the value in order to continue execution of the sub‐selection sets.

An example query illustrating parallel fields with the same name with sub‐selections.

{
  me {
    firstName
  }
  me {
    lastName
  }
}

After resolving the value forme, the selection sets are merged together sofirstNameandlastNamecan be resolved for one value.

MergeSelectionSets

(

fields

)

  1. Let selectionSet be an empty list.
  2. For each field in fields :
    1. Let fieldSelectionSet be the selection set of field .
    2. If fieldSelectionSet is null or empty, continue to the next field.
    3. Append all selections in fieldSelectionSet to selectionSet .
  3. Return selectionSet .

results matching ""

    No results matching ""