Skip to content

Latest commit

 

History

History
246 lines (106 loc) · 3.07 KB

ExecutionResult.md

File metadata and controls

246 lines (106 loc) · 3.07 KB

ExecutionResult

Returned after query execution.

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()

  • Full name: \GraphQL\Executor\ExecutionResult
  • This class implements: \JsonSerializable

Properties

data

Data collected from resolvers during query execution

public array $data

errors

Errors registered during query execution.

public \GraphQL\Error\Error[] $errors

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


extensions

User-defined serializable array of extensions included in serialized result.

public array $extensions

Conforms to


errorFormatter

private callable $errorFormatter

errorsHandler

private callable $errorsHandler

Methods

__construct

public __construct(array $data = null, \GraphQL\Error\Error[] $errors = [], array $extensions = []): mixed

Parameters:

Parameter Type Description
$data array
$errors \GraphQL\Error\Error[]
$extensions array

setErrorFormatter

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

public setErrorFormatter(callable $errorFormatter): self

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

Default formatter is "GraphQL\Error\FormattedError::createFromException"

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

Parameters:

Parameter Type Description
$errorFormatter callable

setErrorsHandler

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

public setErrorsHandler(callable $handler): self

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

Default handler is: function (array $errors, callable $formatter) { return array_map($formatter, $errors); }

Parameters:

Parameter Type Description
$handler callable

jsonSerialize

public jsonSerialize(): array

toArray

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

public toArray(int $debug = DebugFlag::NONE): array

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 \GraphQL\Error\DebugFlag

Parameters:

Parameter Type Description
$debug int