WooCommerce Code Reference

AST
in package

Various utilities dealing with AST.

Table of Contents

astFromValue()  : (\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\ValueNode&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node)|null
Produces a Automattic\WooCommerce\Vendor\GraphQL Value AST given a PHP value.
concatAST()  : DocumentNode
Provided a collection of ASTs, presumably each from different files, concatenate the ASTs together into batched AST, useful for validating many Automattic\WooCommerce\Vendor\GraphQL source files which together represent one conceptual application.
fromArray()  : Node
Convert representation of AST as an associative array to instance of Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node.
getOperationAST()  : OperationDefinitionNode|null
Returns the operation within a document by name.
toArray()  : array<string, mixed>
Convert AST node to serializable array.
typeFromAST()  : Type|null
Returns type definition for given AST Type node.
valueFromAST()  : mixed
Produces a PHP value given a Automattic\WooCommerce\Vendor\GraphQL Value AST.
valueFromASTUntyped()  : mixed
Produces a PHP value given a Automattic\WooCommerce\Vendor\GraphQL Value AST.
isMissingVariable()  : bool
Returns true if the provided valueNode is a variable which is not defined in the set of variables.

Methods

astFromValue()

Produces a Automattic\WooCommerce\Vendor\GraphQL Value AST given a PHP value.

public static astFromValue(mixed $value, InputType|Type $type) : (\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\ValueNode&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node)|null

Optionally, a Automattic\WooCommerce\Vendor\GraphQL type may be provided, which will be used to disambiguate between value primitives.

| PHP Value | Automattic\WooCommerce\Vendor\GraphQL Value | | ------------- | -------------------- | | Object | Input Object | | Assoc Array | Input Object | | Array | List | | Boolean | Boolean | | String | String / Enum Value | | Int | Int | | Float | Int / Float | | Mixed | Enum Value | | null | NullValue |

Parameters
$value : mixed
$type : InputType|Type
Tags
throws
JsonException
throws
InvariantViolation
throws
SerializationError
Return values
(\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\ValueNode&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node)|null

concatAST()

Provided a collection of ASTs, presumably each from different files, concatenate the ASTs together into batched AST, useful for validating many Automattic\WooCommerce\Vendor\GraphQL source files which together represent one conceptual application.

public static concatAST(array<string|int, DocumentNode$documents) : DocumentNode
Parameters
$documents : array<string|int, DocumentNode>
Return values
DocumentNode

fromArray()

Convert representation of AST as an associative array to instance of Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node.

public static fromArray(array<string, mixed> $node) : Node

For example:

AST::fromArray([
    'kind' => 'ListValue',
    'values' => [
        ['kind' => 'StringValue', 'value' => 'my str'],
        ['kind' => 'StringValue', 'value' => 'my other str']
    ],
    'loc' => ['start' => 21, 'end' => 25]
]);

Will produce instance of ListValueNode where values prop is a lazily-evaluated NodeList returning instances of StringValueNode on access.

This is a reverse operation for AST::toArray($node)

Parameters
$node : array<string, mixed>
Tags
throws
JsonException
throws
InvariantViolation
Return values
Node

toArray()

Convert AST node to serializable array.

public static toArray(Node $node) : array<string, mixed>
Parameters
$node : Node
Return values
array<string, mixed>

valueFromAST()

Produces a PHP value given a Automattic\WooCommerce\Vendor\GraphQL Value AST.

public static valueFromAST((\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\ValueNode&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node)|null $valueNode, Type $type[, array<string, mixed>|null $variables = null ][, Schema|null $schema = null ]) : mixed

A Automattic\WooCommerce\Vendor\GraphQL type must be provided, which will be used to interpret different Automattic\WooCommerce\Vendor\GraphQL Value literals.

Returns null when the value could not be validly coerced according to the provided type.

| Automattic\WooCommerce\Vendor\GraphQL Value | PHP Value | | -------------------- | ------------- | | Input Object | Assoc Array | | List | Array | | Boolean | Boolean | | String | String | | Int / Float | Int / Float | | Enum Value | Mixed | | Null Value | null |

Parameters
$valueNode : (\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\ValueNode&\Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node)|null
$type : Type
$variables : array<string, mixed>|null = null
$schema : Schema|null = null
Tags
throws
Exception
Return values
mixed

valueFromASTUntyped()

Produces a PHP value given a Automattic\WooCommerce\Vendor\GraphQL Value AST.

public static valueFromASTUntyped(Node $valueNode[, array<string, mixed>|null $variables = null ]) : mixed

Unlike valueFromAST(), no type is provided. The resulting PHP value will reflect the provided Automattic\WooCommerce\Vendor\GraphQL value AST.

| Automattic\WooCommerce\Vendor\GraphQL Value | PHP Value | | -------------------- | ------------- | | Input Object | Assoc Array | | List | Array | | Boolean | Boolean | | String | String | | Int / Float | Int / Float | | Enum | Mixed | | Null | null |

Parameters
$valueNode : Node
$variables : array<string, mixed>|null = null
Tags
throws
Exception
Return values
mixed

isMissingVariable()

Returns true if the provided valueNode is a variable which is not defined in the set of variables.

private static isMissingVariable(ValueNode|Node $valueNode, array<string, mixed>|null $variables) : bool
Parameters
$valueNode : ValueNode|Node
$variables : array<string, mixed>|null
Return values
bool