WooCommerce Code Reference

GraphQL
in package

This is the primary facade for fulfilling Automattic\WooCommerce\Vendor\GraphQL operations.

See related documentation.

Tags
phpstan-import-type

ArgsMapper from Executor

phpstan-import-type

FieldResolver from Executor

see
GraphQLTest

Table of Contents

executeQuery()  : ExecutionResult
Executes graphql query.
getStandardDirectives()  : array<string, Directive>
Returns directives defined in Automattic\WooCommerce\Vendor\GraphQL spec.
getStandardTypes()  : array<string, ScalarType>
Returns built-in scalar types defined in Automattic\WooCommerce\Vendor\GraphQL spec.
getStandardValidationRules()  : array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule>, ValidationRule>
Returns standard validation rules implementing Automattic\WooCommerce\Vendor\GraphQL spec.
overrideStandardTypes()  : void
Replaces standard types with types from this list (matching by name).
promiseToExecute()  : Promise
Same as executeQuery(), but requires PromiseAdapter and always returns a Promise.
setDefaultArgsMapper()  : void
Set default args mapper implementation.
setDefaultFieldResolver()  : void
Set default resolver implementation.

Methods

executeQuery()

Executes graphql query.

public static executeQuery(Schema $schema, string|DocumentNode $source[, mixed $rootValue = null ][, mixed $contextValue = null ][, array<string, mixed>|null $variableValues = null ][, string|null $operationName = null ][, callable|null $fieldResolver = null ][, array<string|int, ValidationRule>|null $validationRules = null ]) : ExecutionResult

More sophisticated Automattic\WooCommerce\Vendor\GraphQL servers, such as those which persist queries, may wish to separate the validation and execution phases to a static time tooling step, and a server runtime step.

Available options:

schema: The Automattic\WooCommerce\Vendor\GraphQL type system to use when validating and executing a query. source: A Automattic\WooCommerce\Vendor\GraphQL language formatted string representing the requested operation. rootValue: The value provided as the first argument to resolver functions on the top level type (e.g. the query object type). contextValue: The context value is provided as an argument to resolver functions after field arguments. It is used to pass shared information useful at any point during executing this query, for example the currently logged in user and connections to databases or other services. If the passed object implements the ScopedContext interface, its clone() method will be called before passing the context down to a field. This allows passing information to child fields in the query tree without affecting sibling or parent fields. variableValues: A mapping of variable name to runtime value to use for all variables defined in the requestString. operationName: The name of the operation to use if requestString contains multiple possible operations. Can be omitted if requestString contains only one operation. fieldResolver: A resolver function to use when one is not provided by the schema. If not provided, the default field resolver is used (which looks for a value on the source value with the field's name). validationRules: A set of rules for query validation step. Default value is all available rules. Empty array would allow to skip query validation (may be convenient for persisted queries which are validated before persisting and assumed valid during execution)

Parameters
$schema : Schema
$source : string|DocumentNode
$rootValue : mixed = null
$contextValue : mixed = null
$variableValues : array<string, mixed>|null = null
$operationName : string|null = null
$fieldResolver : callable|null = null
$validationRules : array<string|int, ValidationRule>|null = null
Tags
throws
Exception
throws
InvariantViolation
Return values
ExecutionResult

getStandardValidationRules()

Returns standard validation rules implementing Automattic\WooCommerce\Vendor\GraphQL spec.

public static getStandardValidationRules() : array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule>, ValidationRule>
Return values
array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule>, ValidationRule>

overrideStandardTypes()

Replaces standard types with types from this list (matching by name).

public static overrideStandardTypes(array<string, ScalarType$types) : void

Standard types not listed here remain untouched.

Parameters
$types : array<string, ScalarType>
Tags
deprecated

prefer per-schema scalar overrides via {@see} or {@see}

throws
InvariantViolation
Return values
void

promiseToExecute()

Same as executeQuery(), but requires PromiseAdapter and always returns a Promise.

public static promiseToExecute(PromiseAdapter $promiseAdapter, Schema $schema, string|DocumentNode $source[, mixed $rootValue = null ][, mixed $context = null ][, array<string, mixed>|null $variableValues = null ][, string|null $operationName = null ][, callable|null $fieldResolver = null ][, array<string|int, ValidationRule>|null $validationRules = null ]) : Promise

Useful for Async PHP platforms.

Parameters
$promiseAdapter : PromiseAdapter
$schema : Schema
$source : string|DocumentNode
$rootValue : mixed = null
$context : mixed = null
$variableValues : array<string, mixed>|null = null
$operationName : string|null = null
$fieldResolver : callable|null = null
$validationRules : array<string|int, ValidationRule>|null = null

Defaults to using all available rules

Tags
throws
Exception
Return values
Promise

setDefaultArgsMapper()

Set default args mapper implementation.

public static setDefaultArgsMapper(callable $fn) : void
Parameters
$fn : callable
Tags
phpstan-param

ArgsMapper $fn

Return values
void

setDefaultFieldResolver()

Set default resolver implementation.

public static setDefaultFieldResolver(callable $fn) : void
Parameters
$fn : callable
Tags
phpstan-param

FieldResolver $fn

Return values
void