Error

GraphQL Errors

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

exception graphql.error.GraphQLError(message: str, nodes: Union[Collection[Node], Node, None] = 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.

__init__(message: str, nodes: Union[Collection[Node], Node, None] = 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) → None

Initialize self. See help(type(self)) for accurate signature.

args
extensions

Extension fields to add to the formatted error

property formatted

Get error formatted according to the specification.

locations

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

A message describing the Error for debugging purposes

Note: should be treated as readonly, despite invariant usage.

nodes

A list of GraphQL AST Nodes corresponding to this error

original_error

The original error thrown from a field resolver during execution

path

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

Error positions

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

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, position, description)

Bases: graphql.error.graphql_error.GraphQLError

A GraphQLError representing a syntax error.

__init__(source, position, description)

Initialize self. See help(type(self)) for accurate signature.

args
extensions
property formatted

Get error formatted according to the specification.

locations
message
nodes
original_error
path
positions
source
with_traceback()

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

graphql.error.format_error(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: Union[Exception, graphql.error.graphql_error.GraphQLError], nodes: Collection[Node], path: Collection[Union[str, int]]) → graphql.error.graphql_error.GraphQLError

Located GraphQL 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.

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.

exception graphql.error.GraphQLError(message: str, nodes: Union[Collection[Node], Node, None] = 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.

__init__(message: str, nodes: Union[Collection[Node], Node, None] = 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) → None

Initialize self. See help(type(self)) for accurate signature.

args
extensions

Extension fields to add to the formatted error

property formatted

Get error formatted according to the specification.

locations

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

A message describing the Error for debugging purposes

Note: should be treated as readonly, despite invariant usage.

nodes

A list of GraphQL AST Nodes corresponding to this error

original_error

The original error thrown from a field resolver during execution

path

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

Error positions

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

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, position, description)

Bases: graphql.error.graphql_error.GraphQLError

A GraphQLError representing a syntax error.

__init__(source, position, description)

Initialize self. See help(type(self)) for accurate signature.

args
extensions
property formatted

Get error formatted according to the specification.

locations
message
nodes
original_error
path
positions
source
with_traceback()

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

graphql.error.format_error(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: Union[Exception, graphql.error.graphql_error.GraphQLError], nodes: Collection[Node], path: Collection[Union[str, int]]) → graphql.error.graphql_error.GraphQLError

Located GraphQL 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.

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.