WooCommerce Code Reference

ExecutionResult
in package
implements JsonSerializable

Returned after [query execution](executing-queries.md).

Represents both - result of successful execution and of a failed one (with errors collected in errors prop).

Could be converted to spec-compliant serializable array using toArray().

Tags
phpstan-type

SerializableError array{ message: string, locations?: array<int, array{line: int, column: int}>, path?: array<int, int|string>, extensions?: array<string, mixed> }

phpstan-type

SerializableErrors list

phpstan-type

SerializableResult array{ data?: array<string, mixed>, errors?: SerializableErrors, extensions?: array<string, mixed> }

phpstan-type

ErrorFormatter callable(\Throwable): SerializableError

phpstan-type

ErrorsHandler callable(list $errors, ErrorFormatter $formatter): SerializableErrors

see
ExecutionResultTest

Interfaces, Classes and Traits

JsonSerializable

Table of Contents

$data  : array<string|int, mixed>|null
Data collected from resolvers during query execution.
$errors  : array<string|int, mixed>
Errors registered during query execution.
$extensions  : array<string|int, mixed>|null
User-defined serializable array of extensions included in serialized result.
$errorFormatter  : callable|null
$errorsHandler  : callable|null
__construct()  : mixed
jsonSerialize()  : array<string|int, mixed>
setErrorFormatter()  : self
Define custom error formatting (must conform to http://facebook.github.io/graphql/#sec-Errors).
setErrorsHandler()  : self
Define custom logic for error handling (filtering, logging, etc).
toArray()  : array<string|int, mixed>
Converts Automattic\WooCommerce\Vendor\GraphQL query result to spec-compliant serializable array using provided errors handler and formatter.

Properties

$errors

Errors registered during query execution.

public array<string|int, mixed> $errors = []

If an error was caused by exception thrown in resolver, $error->getPrevious() would contain original exception.

Methods

__construct()

public __construct([array<string, mixed>|null $data = null ][, array<int, Error$errors = [] ][, array<string, mixed> $extensions = [] ]) : mixed
Parameters
$data : array<string, mixed>|null = null
$errors : array<int, Error> = []
$extensions : array<string, mixed> = []
Return values
mixed

setErrorFormatter()

Define custom error formatting (must conform to http://facebook.github.io/graphql/#sec-Errors).

public setErrorFormatter(callable|null $errorFormatter) : self

Expected signature is: function (Automattic\WooCommerce\Vendor\GraphQL\Error\Error $error): array

Default formatter is "Automattic\WooCommerce\Vendor\GraphQL\Error\FormattedError::createFromException"

Expected returned value must be an array: array( 'message' => 'errorMessage', // ... other keys );

Parameters
$errorFormatter : callable|null
Tags
phpstan-param

ErrorFormatter|null $errorFormatter

Return values
self

setErrorsHandler()

Define custom logic for error handling (filtering, logging, etc).

public setErrorsHandler(callable|null $errorsHandler) : self

Expected handler signature is: fn (array $errors, callable $formatter): array

Default handler is: fn (array $errors, callable $formatter): array => array_map($formatter, $errors)

Parameters
$errorsHandler : callable|null
Tags
phpstan-param

ErrorsHandler|null $errorsHandler

Return values
self

toArray()

Converts Automattic\WooCommerce\Vendor\GraphQL query result to spec-compliant serializable array using provided errors handler and formatter.

public toArray([int $debug = DebugFlag::NONE ]) : array<string|int, mixed>

If debug argument is passed, output of error formatter is enriched which debugging information ("debugMessage", "trace" keys depending on flags).

$debug argument must sum of flags from @see \Automattic\WooCommerce\Vendor\GraphQL\Error\DebugFlag

Parameters
$debug : int = DebugFlag::NONE
Tags
phpstan-return

SerializableResult

Return values
array<string|int, mixed>