Error

GraphQL Errors

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

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

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.

extensions

Extension fields to add to the formatted error

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.

exception graphql.error.GraphQLSyntaxError(source, position, description)

A GraphQLError representing a syntax error.

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: Sequence[Node], path: Sequence[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.

graphql.error.INVALID = <INVALID>

Symbol for invalid or undefined values

This singleton object is used to describe invalid or undefined values. It corresponds to the undefined value in GraphQL.js.