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
Data collected from resolvers during query execution
public array $data
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.
User-defined serializable array of extensions included in serialized result.
public array $extensions
Conforms to
private callable $errorFormatter
private callable $errorsHandler
public __construct(array $data = null, \GraphQL\Error\Error[] $errors = [], array $extensions = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$data |
array | |
$errors |
\GraphQL\Error\Error[] | |
$extensions |
array |
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 |
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 |
public jsonSerialize(): array
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 |