Error
extends Exception
in package
implements
JsonSerializable, ClientAware
Describes an Error found during the parse, validate, or execute phases of performing a GraphQL operation. In addition to a message and stack trace, it also includes information about the locations in a GraphQL document and/or execution result that correspond to the Error.
When the error was caused by an exception thrown in resolver, original exception
is available via getPrevious()
.
Also read related docs on error handling
Class extends standard PHP \Exception
, so all standard methods of base \Exception
class
are available in addition to those listed below.
Interfaces, Classes, Traits and Enums
- JsonSerializable
- ClientAware
- This interface is used for [default error formatting](error-handling.md).
Table of Contents
- CATEGORY_GRAPHQL = 'graphql'
- CATEGORY_INTERNAL = 'internal'
- $nodes : array<string|int, Node>|null
- An array of GraphQL AST Nodes corresponding to this error.
- $path : array<string|int, mixed>|null
- An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.
- $category : string
- $extensions : array<string|int, mixed>|null
- $isClientSafe : bool
- $locations : array<string|int, SourceLocation>
- Lazily initialized.
- $positions : array<string|int, int>
- $source : Source|null
- The source GraphQL document for the first location of this error.
- __construct() : mixed
- __toString() : string
- createLocatedError() : Error
- Given an arbitrary Error, presumably thrown while attempting to execute a GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Error.
- formatError() : array<string|int, mixed>
- getCategory() : string
- Returns string describing a category of the error.
- getExtensions() : array<string|int, mixed>
- getLocations() : array<string|int, SourceLocation>
- An array of locations within the source GraphQL document which correspond to this error.
- getNodes() : array<string|int, Node>|null
- getPath() : array<string|int, mixed>|null
- Returns an array describing the path from the root value to the field which produced this error.
- getPositions() : array<string|int, int>
- getSource() : Source|null
- isClientSafe() : bool
- Returns true when exception message is safe to be displayed to a client.
- jsonSerialize() : mixed
- Specify data which should be serialized to JSON
- toSerializableArray() : array<string|int, mixed>
- Returns array representation of error suitable for serialization
Constants
CATEGORY_GRAPHQL
public
mixed
CATEGORY_GRAPHQL
= 'graphql'
CATEGORY_INTERNAL
public
mixed
CATEGORY_INTERNAL
= 'internal'
Properties
$nodes
An array of GraphQL AST Nodes corresponding to this error.
public
array<string|int, Node>|null
$nodes
$path
An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.
public
array<string|int, mixed>|null
$path
$category
protected
string
$category
$extensions
protected
array<string|int, mixed>|null
$extensions
$isClientSafe
private
bool
$isClientSafe
$locations
Lazily initialized.
private
array<string|int, SourceLocation>
$locations
$positions
private
array<string|int, int>
$positions
$source
The source GraphQL document for the first location of this error.
private
Source|null
$source
Note that if this Error represents more than one node, the source may not represent nodes after the first node.
Methods
__construct()
public
__construct([string $message = '' ][, Node|array<string|int, Node>|Traversable|null $nodes = null ][, Source|null $source = null ][, array<string|int, mixed> $positions = [] ][, array<string|int, mixed>|null $path = null ][, Throwable $previous = null ][, array<string|int, mixed> $extensions = [] ]) : mixed
Parameters
- $message : string = ''
- $nodes : Node|array<string|int, Node>|Traversable|null = null
- $source : Source|null = null
- $positions : array<string|int, mixed> = []
- $path : array<string|int, mixed>|null = null
- $previous : Throwable = null
- $extensions : array<string|int, mixed> = []
Return values
mixed —__toString()
public
__toString() : string
Return values
string —createLocatedError()
Given an arbitrary Error, presumably thrown while attempting to execute a GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Error.
public
static createLocatedError(mixed $error[, array<string|int, Node>|null $nodes = null ][, array<string|int, mixed>|null $path = null ]) : Error
Parameters
- $error : mixed
- $nodes : array<string|int, Node>|null = null
- $path : array<string|int, mixed>|null = null
Return values
Error —formatError()
public
static formatError(Error $error) : array<string|int, mixed>
Parameters
- $error : Error
Return values
array<string|int, mixed> —getCategory()
Returns string describing a category of the error.
public
getCategory() : string
Tags
Return values
string —getExtensions()
public
getExtensions() : array<string|int, mixed>
Return values
array<string|int, mixed> —getLocations()
An array of locations within the source GraphQL document which correspond to this error.
public
getLocations() : array<string|int, SourceLocation>
Each entry has information about line
and column
within source GraphQL document:
$location->line;
$location->column;
Errors during validation often contain multiple locations, for example to point out to field mentioned in multiple fragments. Errors during execution include a single location, the field which produced the error.
Return values
array<string|int, SourceLocation> —getNodes()
public
getNodes() : array<string|int, Node>|null
Return values
array<string|int, Node>|null —getPath()
Returns an array describing the path from the root value to the field which produced this error.
public
getPath() : array<string|int, mixed>|null
Only included for execution errors.
Return values
array<string|int, mixed>|null —getPositions()
public
getPositions() : array<string|int, int>
Return values
array<string|int, int> —getSource()
public
getSource() : Source|null
Return values
Source|null —isClientSafe()
Returns true when exception message is safe to be displayed to a client.
public
isClientSafe() : bool
Tags
Return values
bool —jsonSerialize()
Specify data which should be serialized to JSON
public
jsonSerialize() : mixed
Tags
Return values
mixed —data which can be serialized by json_encode, which is a value of any type other than a resource.
toSerializableArray()
Returns array representation of error suitable for serialization
public
toSerializableArray() : array<string|int, mixed>