Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

ResolveInfo::getFieldSelectionWithAliasespublicWC 1.0

Returns names and args of all fields selected in query for $this->fieldName up to $depth levels, including aliases.

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 ( ... )),
						  ],
					  ],
				  ],
			  ],
		 ],
	 ],
 ],

]

Method of the class: ResolveInfo{}

No Hooks.

Returns

Array. mixed>

Usage

$ResolveInfo = new ResolveInfo();
$ResolveInfo->getFieldSelectionWithAliases( $depth ): array;
$depth(int)
How many levels to include in the output beyond the first.

ResolveInfo::getFieldSelectionWithAliases() code WC 10.9.1

public function getFieldSelectionWithAliases(int $depth = 0): array
{
    $fields = [];

    foreach ($this->fieldNodes as $fieldNode) {
        $selectionSet = $fieldNode->selectionSet;
        if ($selectionSet !== null) {
            $field = $this->parentType->getField($fieldNode->name->value);
            $fieldType = $field->getType();

            $fields = array_merge_recursive(
                $fields,
                $this->foldSelectionWithAlias($selectionSet, $depth, $fieldType)
            );
        }
    }

    return $fields;
}