ReferenceExecutor
in package
implements
ExecutorImplementation
Interfaces, Classes, Traits and Enums
Table of Contents
- $exeContext : ExecutionContext
- $subFieldCache : SplObjectStorage
- $UNDEFINED : object
- create() : ExecutorImplementation
- doExecute() : Promise
- Returns promise of {@link ExecutionResult}. Promise should always resolve, never reject.
- __construct() : mixed
- buildExecutionContext() : ExecutionContext|array<string|int, Error>
- Constructs an ExecutionContext object from the arguments passed to execute, which we will pass throughout the other execution methods.
- buildResponse() : ExecutionResult|Promise
- collectAndExecuteSubfields() : array<string|int, mixed>|Promise|stdClass
- collectFields() : ArrayObject
- Given a selectionSet, adds all of the fields in that selection to the passed in map of fields, and returns it at the end.
- collectSubFields() : ArrayObject
- A memoized collection of relevant subfields with regard to the return type. Memoizing ensures the subfields are not repeatedly calculated, which saves overhead when resolving lists of values.
- completeAbstractValue() : array<string|int, mixed>|Promise|stdClass
- Complete a value of an abstract type by determining the runtime object type of that value, then complete the value for that type.
- completeLeafValue() : mixed
- Complete a Scalar or Enum by serializing to a valid value, throwing if serialization is not possible.
- completeListValue() : array<string|int, mixed>|Promise|stdClass
- Complete a list value by completing each item in the list with the inner type.
- completeObjectValue() : array<string|int, mixed>|Promise|stdClass
- Complete an Object value by executing all sub-selections.
- completeValue() : array<string|int, mixed>|mixed|Promise|null
- Implements the instructions for completeValue as defined in the "Field entries" section of the spec.
- completeValueCatchingError() : array<string|int, mixed>|Promise|stdClass|null
- This is a small wrapper around completeValue which detects and logs errors in the execution context.
- defaultTypeResolver() : Promise|Type|string|null
- If a resolveType function is not given, then a default resolve behavior is used which attempts two strategies:
- doesFragmentConditionMatch() : bool
- Determines if a fragment is applicable to the given type.
- ensureValidRuntimeType() : ObjectType
- executeFields() : Promise|stdClass|array<string|int, mixed>
- Implements the "Evaluating selection sets" section of the spec for "read" mode.
- executeFieldsSerially() : array<string|int, mixed>|Promise|stdClass
- Implements the "Evaluating selection sets" section of the spec for "write" mode.
- executeOperation() : array<string|int, mixed>|Promise|stdClass|null
- Implements the "Evaluating operations" section of the spec.
- fixResultsIfEmptyArray() : array<string|int, mixed>|stdClass|mixed
- Differentiate empty objects from empty lists.
- getFieldDef() : FieldDefinition|null
- This method looks up the field on the given type definition.
- getFieldEntryKey() : string
- Implements the logic to compute the key of a given fields entry
- getOperationRootType() : ObjectType
- Extracts the root type of the operation from the schema.
- getPromise() : Promise|null
- Only returns the value if it acts like a Promise, i.e. has a "then" function, otherwise returns null.
- handleFieldError() : void
- invalidReturnTypeError() : Error
- isPromise() : bool
- promiseForAssocArray() : Promise
- Transform an associative array with Promises to a Promise which resolves to an associative array where all Promises were resolved.
- promiseReduce() : Promise|mixed|null
- Similar to array_reduce(), however the reducing callback may return a Promise, in which case reduction will continue after each promise resolves.
- resolveField() : array<string|int, mixed>|Throwable|mixed|null
- Resolves the field on the given root value.
- resolveFieldValueOrError() : Throwable|Promise|mixed
- Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField` function.
- shouldIncludeNode() : bool
- Determines if a field should be included based on the @include and @skip directives, where @skip has higher precedence than @include.
Properties
$exeContext
protected
ExecutionContext
$exeContext
$subFieldCache
protected
SplObjectStorage
$subFieldCache
$UNDEFINED
protected
static object
$UNDEFINED
Methods
create()
public
static create(PromiseAdapter $promiseAdapter, Schema $schema, DocumentNode $documentNode, mixed $rootValue, mixed $contextValue, array<string|int, mixed>|Traversable $variableValues, string|null $operationName, callable $fieldResolver) : ExecutorImplementation
Parameters
- $promiseAdapter : PromiseAdapter
- $schema : Schema
- $documentNode : DocumentNode
- $rootValue : mixed
- $contextValue : mixed
- $variableValues : array<string|int, mixed>|Traversable
- $operationName : string|null
- $fieldResolver : callable
Return values
ExecutorImplementation —doExecute()
Returns promise of {@link ExecutionResult}. Promise should always resolve, never reject.
public
doExecute() : Promise
Return values
Promise —__construct()
protected
__construct(ExecutionContext $context) : mixed
Parameters
- $context : ExecutionContext
Return values
mixed —buildExecutionContext()
Constructs an ExecutionContext object from the arguments passed to execute, which we will pass throughout the other execution methods.
protected
static buildExecutionContext(Schema $schema, DocumentNode $documentNode, mixed $rootValue, mixed $contextValue, array<string|int, mixed>|Traversable $rawVariableValues[, string|null $operationName = null ][, callable|null $fieldResolver = null ][, PromiseAdapter|null $promiseAdapter = null ]) : ExecutionContext|array<string|int, Error>
Parameters
- $schema : Schema
- $documentNode : DocumentNode
- $rootValue : mixed
- $contextValue : mixed
- $rawVariableValues : array<string|int, mixed>|Traversable
- $operationName : string|null = null
- $fieldResolver : callable|null = null
- $promiseAdapter : PromiseAdapter|null = null
Return values
ExecutionContext|array<string|int, Error> —buildResponse()
protected
buildResponse(mixed|Promise|null $data) : ExecutionResult|Promise
Parameters
- $data : mixed|Promise|null
Return values
ExecutionResult|Promise —collectAndExecuteSubfields()
protected
collectAndExecuteSubfields(ObjectType $returnType, ArrayObject $fieldNodes, array<string|int, string|int> $path, mixed &$result) : array<string|int, mixed>|Promise|stdClass
Parameters
- $returnType : ObjectType
- $fieldNodes : ArrayObject
- $path : array<string|int, string|int>
- $result : mixed
Tags
Return values
array<string|int, mixed>|Promise|stdClass —collectFields()
Given a selectionSet, adds all of the fields in that selection to the passed in map of fields, and returns it at the end.
protected
collectFields(ObjectType $runtimeType, SelectionSetNode $selectionSet, ArrayObject $fields, ArrayObject $visitedFragmentNames) : ArrayObject
CollectFields requires the "runtime type" of an object. For a field which returns an Interface or Union type, the "runtime type" will be the actual Object type returned by that field.
Parameters
- $runtimeType : ObjectType
- $selectionSet : SelectionSetNode
- $fields : ArrayObject
- $visitedFragmentNames : ArrayObject
Return values
ArrayObject —collectSubFields()
A memoized collection of relevant subfields with regard to the return type. Memoizing ensures the subfields are not repeatedly calculated, which saves overhead when resolving lists of values.
protected
collectSubFields(ObjectType $returnType, ArrayObject $fieldNodes) : ArrayObject
Parameters
- $returnType : ObjectType
- $fieldNodes : ArrayObject
Return values
ArrayObject —completeAbstractValue()
Complete a value of an abstract type by determining the runtime object type of that value, then complete the value for that type.
protected
completeAbstractValue(AbstractType $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array<string|int, string|int> $path, array<string|int, mixed> &$result) : array<string|int, mixed>|Promise|stdClass
Parameters
- $returnType : AbstractType
- $fieldNodes : ArrayObject
- $info : ResolveInfo
- $path : array<string|int, string|int>
- $result : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>|Promise|stdClass —completeLeafValue()
Complete a Scalar or Enum by serializing to a valid value, throwing if serialization is not possible.
protected
completeLeafValue(LeafType $returnType, mixed &$result) : mixed
Parameters
- $returnType : LeafType
- $result : mixed
Tags
Return values
mixed —completeListValue()
Complete a list value by completing each item in the list with the inner type.
protected
completeListValue(ListOfType $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array<string|int, string|int> $path, array<string|int, mixed>|Traversable &$results) : array<string|int, mixed>|Promise|stdClass
Parameters
- $returnType : ListOfType
- $fieldNodes : ArrayObject
- $info : ResolveInfo
- $path : array<string|int, string|int>
- $results : array<string|int, mixed>|Traversable
Tags
Return values
array<string|int, mixed>|Promise|stdClass —completeObjectValue()
Complete an Object value by executing all sub-selections.
protected
completeObjectValue(ObjectType $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array<string|int, string|int> $path, mixed &$result) : array<string|int, mixed>|Promise|stdClass
Parameters
- $returnType : ObjectType
- $fieldNodes : ArrayObject
- $info : ResolveInfo
- $path : array<string|int, string|int>
- $result : mixed
Tags
Return values
array<string|int, mixed>|Promise|stdClass —completeValue()
Implements the instructions for completeValue as defined in the "Field entries" section of the spec.
protected
completeValue(Type $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array<string|int, string|int> $path, mixed &$result) : array<string|int, mixed>|mixed|Promise|null
If the field type is Non-Null, then this recursively completes the value for the inner type. It throws a field error if that completion returns null, as per the "Nullability" section of the spec.
If the field type is a List, then this recursively completes the value for the inner type on each item in the list.
If the field type is a Scalar or Enum, ensures the completed value is a legal
value of the type by calling the serialize
method of GraphQL type
definition.
If the field is an abstract type, determine the runtime type of the value and then complete based on that type
Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all sub-selections.
Parameters
- $returnType : Type
- $fieldNodes : ArrayObject
- $info : ResolveInfo
- $path : array<string|int, string|int>
- $result : mixed
Tags
Return values
array<string|int, mixed>|mixed|Promise|null —completeValueCatchingError()
This is a small wrapper around completeValue which detects and logs errors in the execution context.
protected
completeValueCatchingError(Type $returnType, ArrayObject $fieldNodes, ResolveInfo $info, array<string|int, string|int> $path, mixed $result) : array<string|int, mixed>|Promise|stdClass|null
Parameters
- $returnType : Type
- $fieldNodes : ArrayObject
- $info : ResolveInfo
- $path : array<string|int, string|int>
- $result : mixed
Return values
array<string|int, mixed>|Promise|stdClass|null —defaultTypeResolver()
If a resolveType function is not given, then a default resolve behavior is used which attempts two strategies:
protected
defaultTypeResolver(mixed|null $value, mixed|null $contextValue, ResolveInfo $info, InterfaceType|UnionType $abstractType) : Promise|Type|string|null
First, See if the provided value has a __typename
field defined, if so, use
that value as name of the resolved type.
Otherwise, test each possible type for the abstract type by calling isTypeOf for the object being coerced, returning the first type that matches.
Parameters
- $value : mixed|null
- $contextValue : mixed|null
- $info : ResolveInfo
- $abstractType : InterfaceType|UnionType
Return values
Promise|Type|string|null —doesFragmentConditionMatch()
Determines if a fragment is applicable to the given type.
protected
doesFragmentConditionMatch(FragmentDefinitionNode|InlineFragmentNode $fragment, ObjectType $type) : bool
Parameters
- $fragment : FragmentDefinitionNode|InlineFragmentNode
- $type : ObjectType
Return values
bool —ensureValidRuntimeType()
protected
ensureValidRuntimeType(string|ObjectType|null $runtimeTypeOrName, InterfaceType|UnionType $returnType, ResolveInfo $info, mixed &$result) : ObjectType
Parameters
- $runtimeTypeOrName : string|ObjectType|null
- $returnType : InterfaceType|UnionType
- $info : ResolveInfo
- $result : mixed
Return values
ObjectType —executeFields()
Implements the "Evaluating selection sets" section of the spec for "read" mode.
protected
executeFields(ObjectType $parentType, mixed $rootValue, array<string|int, string|int> $path, ArrayObject $fields) : Promise|stdClass|array<string|int, mixed>
Parameters
- $parentType : ObjectType
- $rootValue : mixed
- $path : array<string|int, string|int>
- $fields : ArrayObject
Return values
Promise|stdClass|array<string|int, mixed> —executeFieldsSerially()
Implements the "Evaluating selection sets" section of the spec for "write" mode.
protected
executeFieldsSerially(ObjectType $parentType, mixed $rootValue, array<string|int, string|int> $path, ArrayObject $fields) : array<string|int, mixed>|Promise|stdClass
Parameters
- $parentType : ObjectType
- $rootValue : mixed
- $path : array<string|int, string|int>
- $fields : ArrayObject
Return values
array<string|int, mixed>|Promise|stdClass —executeOperation()
Implements the "Evaluating operations" section of the spec.
protected
executeOperation(OperationDefinitionNode $operation, mixed $rootValue) : array<string|int, mixed>|Promise|stdClass|null
Parameters
- $operation : OperationDefinitionNode
- $rootValue : mixed
Return values
array<string|int, mixed>|Promise|stdClass|null —fixResultsIfEmptyArray()
Differentiate empty objects from empty lists.
protected
static fixResultsIfEmptyArray(array<string|int, mixed>|mixed $results) : array<string|int, mixed>|stdClass|mixed
Parameters
- $results : array<string|int, mixed>|mixed
Tags
Return values
array<string|int, mixed>|stdClass|mixed —getFieldDef()
This method looks up the field on the given type definition.
protected
getFieldDef(Schema $schema, ObjectType $parentType, string $fieldName) : FieldDefinition|null
It has special casing for the two introspection fields, __schema and __typename. __typename is special because it can always be queried as a field, even in situations where no other fields are allowed, like on a Union. __schema could get automatically added to the query type, but that would require mutating type definitions, which would cause issues.
Parameters
- $schema : Schema
- $parentType : ObjectType
- $fieldName : string
Return values
FieldDefinition|null —getFieldEntryKey()
Implements the logic to compute the key of a given fields entry
protected
static getFieldEntryKey(FieldNode $node) : string
Parameters
- $node : FieldNode
Return values
string —getOperationRootType()
Extracts the root type of the operation from the schema.
protected
getOperationRootType(Schema $schema, OperationDefinitionNode $operation) : ObjectType
Parameters
- $schema : Schema
- $operation : OperationDefinitionNode
Tags
Return values
ObjectType —getPromise()
Only returns the value if it acts like a Promise, i.e. has a "then" function, otherwise returns null.
protected
getPromise(mixed $value) : Promise|null
Parameters
- $value : mixed
Return values
Promise|null —handleFieldError()
protected
handleFieldError(mixed $rawError, ArrayObject $fieldNodes, array<string|int, string|int> $path, Type $returnType) : void
Parameters
- $rawError : mixed
- $fieldNodes : ArrayObject
- $path : array<string|int, string|int>
- $returnType : Type
Tags
Return values
void —invalidReturnTypeError()
protected
invalidReturnTypeError(ObjectType $returnType, array<string|int, mixed> $result, ArrayObject $fieldNodes) : Error
Parameters
- $returnType : ObjectType
- $result : array<string|int, mixed>
- $fieldNodes : ArrayObject
Return values
Error —isPromise()
protected
isPromise(mixed $value) : bool
Parameters
- $value : mixed
Return values
bool —promiseForAssocArray()
Transform an associative array with Promises to a Promise which resolves to an associative array where all Promises were resolved.
protected
promiseForAssocArray(array<string, \GraphQL\Executor\Promise\Promise|mixed> $assoc) : Promise
Parameters
- $assoc : array<string, \GraphQL\Executor\Promise\Promise|mixed>
Return values
Promise —promiseReduce()
Similar to array_reduce(), however the reducing callback may return a Promise, in which case reduction will continue after each promise resolves.
protected
promiseReduce(array<string|int, mixed> $values, callable $callback, Promise|mixed|null $initialValue) : Promise|mixed|null
If the callback does not return a Promise, then this function will also not return a Promise.
Parameters
- $values : array<string|int, mixed>
- $callback : callable
- $initialValue : Promise|mixed|null
Return values
Promise|mixed|null —resolveField()
Resolves the field on the given root value.
protected
resolveField(ObjectType $parentType, mixed $rootValue, ArrayObject $fieldNodes, array<string|int, string|int> $path) : array<string|int, mixed>|Throwable|mixed|null
In particular, this figures out the value that the field returns by calling its resolve function, then calls completeValue to complete promises, serialize scalars, or execute the sub-selection-set for objects.
Parameters
- $parentType : ObjectType
- $rootValue : mixed
- $fieldNodes : ArrayObject
- $path : array<string|int, string|int>
Return values
array<string|int, mixed>|Throwable|mixed|null —resolveFieldValueOrError()
Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField` function.
protected
resolveFieldValueOrError(FieldDefinition $fieldDef, FieldNode $fieldNode, callable $resolveFn, mixed $rootValue, ResolveInfo $info) : Throwable|Promise|mixed
Returns the result of resolveFn or the abrupt-return Error object.
Parameters
- $fieldDef : FieldDefinition
- $fieldNode : FieldNode
- $resolveFn : callable
- $rootValue : mixed
- $info : ResolveInfo
Return values
Throwable|Promise|mixed —shouldIncludeNode()
Determines if a field should be included based on the @include and @skip directives, where @skip has higher precedence than @include.
protected
shouldIncludeNode(FragmentSpreadNode|FieldNode|InlineFragmentNode $node) : bool