ResolveInfo
in package
Structure containing information useful for field resolution process.
Passed as 4th argument to every field resolver. See docs on field resolving (data fetching).
Tags
Table of Contents
- $fieldDefinition : FieldDefinition
- The definition of the field being resolved.
- $fieldName : string
- The name of the field being resolved.
- $fieldNodes : ArrayObject
- AST of all nodes referencing this field in the query.
- $fragments : array<string|int, mixed>
- AST of all fragments defined in query.
- $operation : OperationDefinitionNode
- AST of operation definition node (query, mutation).
- $parentType : ObjectType
- Parent type of the field being resolved.
- $path : array<string|int, mixed>
- Path to this field from the very root value. When fields are aliased, the path includes aliases.
- $returnType : Type
- Expected return type of the field being resolved.
- $rootValue : mixed
- Root value passed to query execution.
- $schema : Schema
- Instance of a schema used for execution.
- $unaliasedPath : array<string|int, mixed>
- Path to this field from the very root value. This will never include aliases.
- $variableValues : array<string|int, mixed>
- Array of variables passed to query execution.
- __construct() : mixed
- getFieldSelection() : array<string, mixed>
- Returns names of all fields selected in query for `$this->fieldName` up to `$depth` levels.
- getFieldSelectionWithAliases() : array<string, mixed>
- Returns names and args of all fields selected in query for `$this->fieldName` up to `$depth` levels, including aliases.
- lookAhead() : QueryPlan
- foldSelectionSet() : array<string, bool>
- foldSelectionWithAlias() : array<string|int, string>
Properties
$fieldDefinition
The definition of the field being resolved.
public
FieldDefinition
$fieldDefinition
$fieldName
The name of the field being resolved.
public
string
$fieldName
$fieldNodes
AST of all nodes referencing this field in the query.
public
ArrayObject
$fieldNodes
$fragments
AST of all fragments defined in query.
public
array<string|int, mixed>
$fragments
= []
$operation
AST of operation definition node (query, mutation).
public
OperationDefinitionNode
$operation
$parentType
Parent type of the field being resolved.
public
ObjectType
$parentType
$path
Path to this field from the very root value. When fields are aliased, the path includes aliases.
public
array<string|int, mixed>
$path
Tags
$returnType
Expected return type of the field being resolved.
public
Type
$returnType
$rootValue
Root value passed to query execution.
public
mixed
$rootValue
$schema
Instance of a schema used for execution.
public
Schema
$schema
$unaliasedPath
Path to this field from the very root value. This will never include aliases.
public
array<string|int, mixed>
$unaliasedPath
Tags
$variableValues
Array of variables passed to query execution.
public
array<string|int, mixed>
$variableValues
= []
Methods
__construct()
public
__construct(FieldDefinition $fieldDefinition, ArrayObject<int, FieldNode> $fieldNodes, ObjectType $parentType, array<int, string|int> $path, Schema $schema, array<string, FragmentDefinitionNode> $fragments, mixed|null $rootValue, OperationDefinitionNode $operation, array<string, mixed> $variableValues[, array<int, string|int> $unaliasedPath = [] ]) : mixed
Parameters
- $fieldDefinition : FieldDefinition
- $fieldNodes : ArrayObject<int, FieldNode>
- $parentType : ObjectType
- $path : array<int, string|int>
- $schema : Schema
- $fragments : array<string, FragmentDefinitionNode>
- $rootValue : mixed|null
- $operation : OperationDefinitionNode
- $variableValues : array<string, mixed>
- $unaliasedPath : array<int, string|int> = []
Tags
Return values
mixed —getFieldSelection()
Returns names of all fields selected in query for `$this->fieldName` up to `$depth` levels.
public
getFieldSelection(int $depth) : array<string, mixed>
Example: { root { id nested { nested1 nested2 { nested3 } } } }
Given this ResolveInfo instance is a part of root field resolution, and $depth === 1, this method will return: [ 'id' => true, 'nested' => [ 'nested1' => true, 'nested2' => true, ], ]
This method does not consider conditional typed fragments. Use it with care for fields of interface and union types.
Parameters
- $depth : int
-
How many levels to include in the output beyond the first
Return values
array<string, mixed> —getFieldSelectionWithAliases()
Returns names and args of all fields selected in query for `$this->fieldName` up to `$depth` levels, including aliases.
public
getFieldSelectionWithAliases(int $depth) : array<string, mixed>
The result maps original field names to a map of selections for that field, including aliases. For each of those selections, you can find the following keys:
- "args" contains the passed arguments for this field/alias (not on an union inline fragment)
- "type" contains the related Type instance found (will be the same for all aliases of a field)
- "selectionSet" contains potential nested fields of this field/alias (only on ObjectType). The structure is recursive from here.
- "unions" contains potential object types contained in an UnionType (only on UnionType). The structure is recursive from here and will go through the selectionSet of the object types.
Example: { root { id nested { nested1(myArg: 1) nested1Bis: nested1 } alias1: nested { nested1(myArg: 2, mySecondAg: "test") } myUnion(myArg: 3) { ...on Nested { nested1(myArg: 4) } ...on MyCustomObject { nested3 } } } }
Given this ResolveInfo instance is a part of root field resolution, $depth === 1, and fields "nested" represents an ObjectType named "Nested", this method will return: [ 'id' => [ 'id' => [ 'args' => [], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\IntType Object ( ... )), ], ], 'nested' => [ 'nested' => [ 'args' => [], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\ObjectType Object ( ... )), 'selectionSet' => [ 'nested1' => [ 'nested1' => [ 'args' => [ 'myArg' => 1, ], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\StringType Object ( ... )), ], 'nested1Bis' => [ 'args' => [], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\StringType Object ( ... )), ], ], ], ], ], 'alias1' => [ 'alias1' => [ 'args' => [], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\ObjectType Object ( ... )), 'selectionSet' => [ 'nested1' => [ 'nested1' => [ 'args' => [ 'myArg' => 2, 'mySecondAg' => "test", ], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\StringType Object ( ... )), ], ], ], ], ], 'myUnion' => [ 'myUnion' => [ 'args' => [ 'myArg' => 3, ], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\UnionType Object ( ... )), 'unions' => [ 'Nested' => [ 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\ObjectType Object ( ... )), 'selectionSet' => [ 'nested1' => [ 'nested1' => [ 'args' => [ 'myArg' => 4, ], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\StringType Object ( ... )), ], ], ], ], 'MyCustomObject' => [ 'type' => Automattic\WooCommerce\Vendor\GraphQL\Tests\Type\TestClasses\MyCustomType Object ( ... )), 'selectionSet' => [ 'nested3' => [ 'nested3' => [ 'args' => [], 'type' => Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\StringType Object ( ... )), ], ], ], ], ], ], ], ]
Parameters
- $depth : int
-
How many levels to include in the output beyond the first
Tags
Return values
array<string, mixed> —lookAhead()
public
lookAhead([QueryPlanOptions $options = [] ]) : QueryPlan
Parameters
- $options : QueryPlanOptions = []
Tags
Return values
QueryPlan —foldSelectionSet()
private
foldSelectionSet(SelectionSetNode $selectionSet, int $descend) : array<string, bool>
Parameters
- $selectionSet : SelectionSetNode
- $descend : int
Return values
array<string, bool> —foldSelectionWithAlias()
private
foldSelectionWithAlias(SelectionSetNode $selectionSet, int $descend, Type $parentType) : array<string|int, string>
Parameters
- $selectionSet : SelectionSetNode
- $descend : int
- $parentType : Type
