Error

GraphQL Errors

The graphql.error package is responsible for creating and formatting GraphQL errors.

exception graphql.error.GraphQLError(message: str, nodes: Optional[Union[Collection[Node], Node]] = None, source: Optional[Source] = None, positions: Optional[Collection[int]] = None, path: Optional[Collection[Union[str, int]]] = None, original_error: Optional[Exception] = None, extensions: Optional[Dict[str, Any]] = None)

Bases: Exception

GraphQL Error

A GraphQLError describes an Error found during the parse, validate, or execute phases of performing a GraphQL operation. In addition to a message, it also includes information about the locations in a GraphQL document and/or execution result that correspond to the Error.

args
extensions: Optional[Dict[str, Any]]

Extension fields to add to the formatted error

property formatted: Dict[str, Any]

Get error formatted according to the specification.

locations: Optional[List[SourceLocation]]

Source locations

A list of (line, column) locations within the source GraphQL document which correspond to this error.

Errors during validation often contain multiple locations, for example to point out two things with the same name. Errors during execution include a single location, the field which produced the error.

message: str

A message describing the Error for debugging purposes

nodes: Optional[List[Node]]

A list of GraphQL AST Nodes corresponding to this error

original_error: Optional[Exception]

The original error thrown from a field resolver during execution

path: Optional[List[Union[str, int]]]

A list of field names and array indexes describing the JSON-path into the execution response which corresponds to this error.

Only included for errors during execution.

positions: Optional[Collection[int]]

Error positions

A list of character offsets within the source GraphQL document which correspond to this error.

source: Optional[Source]

The source GraphQL document for the first location of this error

Note that if this Error represents more than one node, the source may not represent nodes after the first node.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception graphql.error.GraphQLSyntaxError(source: Source, position: int, description: str)

Bases: graphql.error.graphql_error.GraphQLError

A GraphQLError representing a syntax error.

args
extensions: Optional[Dict[str, Any]]

Extension fields to add to the formatted error

property formatted: Dict[str, Any]

Get error formatted according to the specification.

locations: Optional[List[SourceLocation]]

Source locations

A list of (line, column) locations within the source GraphQL document which correspond to this error.

Errors during validation often contain multiple locations, for example to point out two things with the same name. Errors during execution include a single location, the field which produced the error.

message: str

A message describing the Error for debugging purposes

nodes: Optional[List[Node]]

A list of GraphQL AST Nodes corresponding to this error

original_error: Optional[Exception]

The original error thrown from a field resolver during execution

path: Optional[List[Union[str, int]]]

A list of field names and array indexes describing the JSON-path into the execution response which corresponds to this error.

Only included for errors during execution.

positions: Optional[Collection[int]]

Error positions

A list of character offsets within the source GraphQL document which correspond to this error.

source: Optional[Source]

The source GraphQL document for the first location of this error

Note that if this Error represents more than one node, the source may not represent nodes after the first node.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

graphql.error.format_error(error: graphql.error.graphql_error.GraphQLError) Dict[str, Any]

Format a GraphQL error.

Given a GraphQLError, format it according to the rules described by the “Response Format, Errors” section of the GraphQL Specification.

graphql.error.located_error(original_error: Exception, nodes: Optional[Union[None, Collection[Node]]], path: Optional[Collection[Union[str, int]]] = None) graphql.error.graphql_error.GraphQLError

Located GraphQL Error

Given an arbitrary Exception, presumably thrown while attempting to execute a GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Exception.

graphql.error.print_error(error: graphql.error.graphql_error.GraphQLError) str

Print a GraphQLError to a string.

Represents useful location information about the error’s position in the source.