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.
- Full name:
\GraphQL\Error\SyntaxError
- Parent class:
\GraphQL\Error\Error
public __construct(\GraphQL\Language\Source $source, int $position, string $description): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$source |
\GraphQL\Language\Source | |
$position |
int | |
$description |
string |
public __construct(string $message = '', \GraphQL\Language\AST\Node|\GraphQL\Language\AST\Node[]|\Traversable|null $nodes = null, ?\GraphQL\Language\Source $source = null, array $positions = [], array|null $path = null, \Throwable $previous = null, array $extensions = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$message |
string | |
$nodes |
\GraphQL\Language\AST\Node|\GraphQL\Language\AST\Node[]|\Traversable|null | |
$source |
?\GraphQL\Language\Source | |
$positions |
array | |
$path |
array|null | |
$previous |
\Throwable | |
$extensions |
array |
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, \GraphQL\Language\AST\Node[]|null $nodes = null, array|null $path = null): \GraphQL\Error\Error
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$error |
mixed | |
$nodes |
\GraphQL\Language\AST\Node[]|null | |
$path |
array|null |
public static formatError(\GraphQL\Error\Error $error): array
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$error |
\GraphQL\Error\Error |
Returns true when exception message is safe to be displayed to a client.
public isClientSafe(): bool
Returns string describing a category of the error.
public getCategory(): string
public getSource(): ?\GraphQL\Language\Source
public getPositions(): int[]
An array of locations within the source GraphQL document which correspond to this error.
public getLocations(): \GraphQL\Language\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.
public getNodes(): \GraphQL\Language\AST\Node[]|null
Returns an array describing the path from the root value to the field which produced this error.
public getPath(): array|null
Only included for execution errors.
public getExtensions(): array
Returns array representation of error suitable for serialization
public toSerializableArray(): array
- Warning: this method is deprecated. This means that this method will likely be removed in a future version.
Specify data which should be serialized to JSON
public jsonSerialize(): mixed
Return Value:
data which can be serialized by json_encode, which is a value of any type other than a resource.
See Also:
public __toString(): string