WooCommerce Code Reference

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
phpstan-import-type

QueryPlanOptions from QueryPlan

phpstan-type

Path list<string|int>

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

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
phpstan-param

Path $path

phpstan-param

Path $unaliasedPath

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
throws
Exception
throws
Error
throws
InvariantViolation
Return values
array<string, mixed>