Skip to content

Latest commit

 

History

History
385 lines (141 loc) · 4.65 KB

SyntaxError.md

File metadata and controls

385 lines (141 loc) · 4.65 KB

SyntaxError

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.

Methods

__construct

public __construct(\GraphQL\Language\Source $source, int $position, string $description): mixed

Parameters:

Parameter Type Description
$source \GraphQL\Language\Source
$position int
$description string

Inherited methods

__construct

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

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, \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

formatError

public static formatError(\GraphQL\Error\Error $error): array
  • This method is static.

Parameters:

Parameter Type Description
$error \GraphQL\Error\Error

isClientSafe

Returns true when exception message is safe to be displayed to a client.

public isClientSafe(): bool

getCategory

Returns string describing a category of the error.

public getCategory(): string

getSource

public getSource(): ?\GraphQL\Language\Source

getPositions

public getPositions(): int[]

getLocations

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.


getNodes

public getNodes(): \GraphQL\Language\AST\Node[]|null

getPath

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.


getExtensions

public getExtensions(): array

toSerializableArray

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.

jsonSerialize

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:


__toString

public __toString(): string