Execution

GraphQL Execution

The graphql.execution package is responsible for the execution phase of fulfilling a GraphQL request.

graphql.execution.execute(schema: graphql.type.schema.GraphQLSchema, document: graphql.language.ast.DocumentNode, root_value: Any = None, context_value: Any = None, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, field_resolver: Optional[Callable[[...], Any]] = None, type_resolver: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]]] = None, middleware: Union[Tuple, List, graphql.execution.middleware.MiddlewareManager, None] = None, execution_context_class: Optional[Type[ExecutionContext]] = None) → Union[Awaitable[graphql.execution.execute.ExecutionResult], graphql.execution.execute.ExecutionResult]

Execute a GraphQL operation.

Implements the “Evaluating requests” section of the GraphQL specification.

Returns an ExecutionResult (if all encountered resolvers are synchronous), or a coroutine object eventually yielding an ExecutionResult.

If the arguments to this function do not result in a legal execution context, a GraphQLError will be thrown immediately explaining the invalid input.

graphql.execution.default_field_resolver(source, info, **args)

Default field resolver.

If a resolve function is not given, then a default resolve behavior is used which takes the property of the source object of the same name as the field and returns it as the result, or if it’s a function, returns the result of calling that function while passing along args and context.

For dictionaries, the field names are used as keys, for all other objects they are used as attribute names.

graphql.execution.default_type_resolver(value: Any, info: graphql.type.definition.GraphQLResolveInfo, abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]) → Union[Awaitable[Union[graphql.type.definition.GraphQLObjectType, str, None]], graphql.type.definition.GraphQLObjectType, str, None]

Default type resolver function.

If a resolve_type function is not given, then a default resolve behavior is used which attempts two strategies:

First, See if the provided value has a __typename field defined, if so, use that value as name of the resolved type.

Otherwise, test each possible type for the abstract type by calling is_type_of for the object being coerced, returning the first type that matches.

class graphql.execution.ExecutionContext(schema: graphql.type.schema.GraphQLSchema, fragments: Dict[str, graphql.language.ast.FragmentDefinitionNode], root_value: Any, context_value: Any, operation: graphql.language.ast.OperationDefinitionNode, variable_values: Dict[str, Any], field_resolver: Callable[[...], Any], type_resolver: Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]], errors: List[graphql.error.graphql_error.GraphQLError], middleware_manager: Optional[graphql.execution.middleware.MiddlewareManager])

Bases: object

Data that must be available at all points during query execution.

Namely, schema of the type system that is currently executing, and the fragments defined in the query document.

__init__(schema: graphql.type.schema.GraphQLSchema, fragments: Dict[str, graphql.language.ast.FragmentDefinitionNode], root_value: Any, context_value: Any, operation: graphql.language.ast.OperationDefinitionNode, variable_values: Dict[str, Any], field_resolver: Callable[[...], Any], type_resolver: Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]], errors: List[graphql.error.graphql_error.GraphQLError], middleware_manager: Optional[graphql.execution.middleware.MiddlewareManager]) → None

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

classmethod build(schema: graphql.type.schema.GraphQLSchema, document: graphql.language.ast.DocumentNode, root_value: Any = None, context_value: Any = None, raw_variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, field_resolver: Optional[Callable[[...], Any]] = None, type_resolver: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]]] = None, middleware: Union[Tuple, List, graphql.execution.middleware.MiddlewareManager, None] = None) → Union[List[graphql.error.graphql_error.GraphQLError], graphql.execution.execute.ExecutionContext]

Build an execution context

Constructs a ExecutionContext object from the arguments passed to execute, which we will pass throughout the other execution methods.

Throws a GraphQLError if a valid execution context cannot be created.

For internal use only.

build_resolve_info(field_def: graphql.type.definition.GraphQLField, field_nodes: List[graphql.language.ast.FieldNode], parent_type: graphql.type.definition.GraphQLObjectType, path: graphql.pyutils.path.Path) → graphql.type.definition.GraphQLResolveInfo

Build the GraphQLResolveInfo object.

For internal use only.

build_response(data: Union[Awaitable[Optional[Dict[str, Any]]], Dict[str, Any], None]) → Union[Awaitable[graphql.execution.execute.ExecutionResult], graphql.execution.execute.ExecutionResult]

Build response.

Given a completed execution context and data, build the (data, errors) response defined by the “Response” section of the GraphQL spec.

collect_and_execute_subfields(return_type: graphql.type.definition.GraphQLObjectType, field_nodes: List[graphql.language.ast.FieldNode], path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Collect sub-fields to execute to complete this value.

collect_fields(runtime_type: graphql.type.definition.GraphQLObjectType, selection_set: graphql.language.ast.SelectionSetNode, fields: Dict[str, List[graphql.language.ast.FieldNode]], visited_fragment_names: Set[str]) → Dict[str, List[graphql.language.ast.FieldNode]]

Collect fields.

Given a selection_set, adds all of the fields in that selection to the passed in map of fields, and returns it at the end.

collect_fields requires the “runtime type” of an object. For a field which returns an Interface or Union type, the “runtime type” will be the actual Object type returned by that field.

For internal use only.

collect_subfields(return_type: graphql.type.definition.GraphQLObjectType, field_nodes: List[graphql.language.ast.FieldNode]) → Dict[str, List[graphql.language.ast.FieldNode]]

Collect subfields.

A cached collection of relevant subfields with regard to the return type is kept in the execution context as _subfields_cache. This ensures the subfields are not repeatedly calculated, which saves overhead when resolving lists of values.

complete_abstract_value(return_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Any], Any]

Complete an abstract value.

Complete a value of an abstract type by determining the runtime object type of that value, then complete the value for that type.

static complete_leaf_value(return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType], result: Any) → Any

Complete a leaf value.

Complete a Scalar or Enum by serializing to a valid value, returning null if serialization is not possible.

complete_list_value(return_type: graphql.type.definition.GraphQLList[typing.Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]][Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Iterable[Any]) → Union[Awaitable[Any], Any]

Complete a list value.

Complete a list value by completing each item in the list with the inner type.

complete_object_value(return_type: graphql.type.definition.GraphQLObjectType, field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Complete an Object value by executing all sub-selections.

complete_value(return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Any], Any]

Complete a value.

Implements the instructions for completeValue as defined in the “Field entries” section of the spec.

If the field type is Non-Null, then this recursively completes the value for the inner type. It throws a field error if that completion returns null, as per the “Nullability” section of the spec.

If the field type is a List, then this recursively completes the value for the inner type on each item in the list.

If the field type is a Scalar or Enum, ensures the completed value is a legal value of the type by calling the serialize method of GraphQL type definition.

If the field is an abstract type, determine the runtime type of the value and then complete based on that type.

Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all sub-selections.

complete_value_catching_error(return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Any], Any]

Complete a value while catching an error.

This is a small wrapper around completeValue which detects and logs errors in the execution context.

context_value: Any = None
does_fragment_condition_match(fragment: Union[graphql.language.ast.FragmentDefinitionNode, graphql.language.ast.InlineFragmentNode], type_: graphql.type.definition.GraphQLObjectType) → bool

Determine if a fragment is applicable to the given type.

ensure_valid_runtime_type(runtime_type_or_name: Union[graphql.type.definition.GraphQLObjectType, str, None], return_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, result: Any) → graphql.type.definition.GraphQLObjectType
errors: List[GraphQLError] = None
execute_fields(parent_type: graphql.type.definition.GraphQLObjectType, source_value: Any, path: Optional[graphql.pyutils.path.Path], fields: Dict[str, List[graphql.language.ast.FieldNode]]) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Execute the given fields concurrently.

Implements the “Evaluating selection sets” section of the spec for “read” mode.

execute_fields_serially(parent_type: graphql.type.definition.GraphQLObjectType, source_value: Any, path: Optional[graphql.pyutils.path.Path], fields: Dict[str, List[graphql.language.ast.FieldNode]]) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Execute the given fields serially.

Implements the “Evaluating selection sets” section of the spec for “write” mode.

execute_operation(operation: graphql.language.ast.OperationDefinitionNode, root_value: Any) → Union[Awaitable[Any], Any, None]

Execute an operation.

Implements the “Evaluating operations” section of the spec.

field_resolver: GraphQLFieldResolver = None
fragments: Dict[str, FragmentDefinitionNode] = None
handle_field_error(raw_error: Exception, field_nodes: List[graphql.language.ast.FieldNode], path: graphql.pyutils.path.Path, return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]) → None
middleware_manager: Optional[MiddlewareManager] = None
operation: OperationDefinitionNode = None
resolve_field(parent_type: graphql.type.definition.GraphQLObjectType, source: Any, field_nodes: List[graphql.language.ast.FieldNode], path: graphql.pyutils.path.Path) → Union[Awaitable[Any], Any]

Resolve the field on the given source object.

In particular, this figures out the value that the field returns by calling its resolve function, then calls complete_value to await coroutine objects, serialize scalars, or execute the sub-selection-set for objects.

resolve_field_value_or_error(field_def: graphql.type.definition.GraphQLField, field_nodes: List[graphql.language.ast.FieldNode], resolve_fn: Callable[[...], Any], source: Any, info: graphql.type.definition.GraphQLResolveInfo) → Union[Exception, Any]

Resolve field to a value or an error.

Isolates the “ReturnOrAbrupt” behavior to not de-opt the resolve_field() method. Returns the result of resolveFn or the abrupt-return Error object.

For internal use only.

root_value: Any = None
schema: GraphQLSchema = None
should_include_node(node: Union[graphql.language.ast.FragmentSpreadNode, graphql.language.ast.FieldNode, graphql.language.ast.InlineFragmentNode]) → bool

Check if node should be included

Determines if a field should be included based on the @include and @skip directives, where @skip has higher precedence than @include.

type_resolver: GraphQLTypeResolver = None
variable_values: Dict[str, Any] = None
class graphql.execution.ExecutionResult

Bases: tuple

The result of GraphQL execution.

  • data is the result of a successful execution of the query.

  • errors is included when any errors occurred as a non-empty list.

__init__()

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

_asdict()

Return a new OrderedDict which maps field names to their values.

_field_defaults = {}
_field_types = {'data': typing.Union[typing.Dict[str, typing.Any], NoneType], 'errors': typing.Union[typing.List[graphql.error.graphql_error.GraphQLError], NoneType]}
_fields = ('data', 'errors')
_fields_defaults = {}
classmethod _make(iterable)

Make a new ExecutionResult object from a sequence or iterable

_replace(**kwds)

Return a new ExecutionResult object replacing specified fields with new values

count()

Return number of occurrences of value.

property data

Alias for field number 0

property errors

Alias for field number 1

index()

Return first index of value.

Raises ValueError if the value is not present.

class graphql.execution.MiddlewareManager(*middlewares: Any)

Bases: object

Manager for the middleware chain.

This class helps to wrap resolver functions with the provided middleware functions and/or objects. The functions take the next middleware function as first argument. If middleware is provided as an object, it must provide a method resolve that is used as the middleware function.

Note that since resolvers return “AwaitableOrValue”s, all middleware functions must be aware of this and check whether values are awaitable before awaiting them.

__init__(*middlewares: Any)

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

_cached_resolvers
_middleware_resolvers
get_field_resolver(field_resolver: Callable[[...], Any]) → Callable[[...], Any]

Wrap the provided resolver with the middleware.

Returns a function that chains the middleware functions with the provided resolver function.

middlewares
graphql.execution.get_directive_values(directive_def: graphql.type.directives.GraphQLDirective, node: Union[graphql.language.ast.ExecutableDefinitionNode, graphql.language.ast.SelectionNode, graphql.language.ast.SchemaDefinitionNode, graphql.language.ast.TypeDefinitionNode, graphql.language.ast.TypeExtensionNode], variable_values: Optional[Dict[str, Any]] = None) → Optional[Dict[str, Any]]

Get coerced argument values based on provided nodes.

Prepares a dict of argument values given a directive definition and an AST node which may contain directives. Optionally also accepts a dict of variable values.

If the directive does not exist on the node, returns None.

graphql.execution.execute(schema: graphql.type.schema.GraphQLSchema, document: graphql.language.ast.DocumentNode, root_value: Any = None, context_value: Any = None, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, field_resolver: Optional[Callable[[...], Any]] = None, type_resolver: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]]] = None, middleware: Union[Tuple, List, graphql.execution.middleware.MiddlewareManager, None] = None, execution_context_class: Optional[Type[ExecutionContext]] = None) → Union[Awaitable[graphql.execution.execute.ExecutionResult], graphql.execution.execute.ExecutionResult]

Execute a GraphQL operation.

Implements the “Evaluating requests” section of the GraphQL specification.

Returns an ExecutionResult (if all encountered resolvers are synchronous), or a coroutine object eventually yielding an ExecutionResult.

If the arguments to this function do not result in a legal execution context, a GraphQLError will be thrown immediately explaining the invalid input.

graphql.execution.default_field_resolver(source, info, **args)

Default field resolver.

If a resolve function is not given, then a default resolve behavior is used which takes the property of the source object of the same name as the field and returns it as the result, or if it’s a function, returns the result of calling that function while passing along args and context.

For dictionaries, the field names are used as keys, for all other objects they are used as attribute names.

class graphql.execution.ExecutionContext(schema: graphql.type.schema.GraphQLSchema, fragments: Dict[str, graphql.language.ast.FragmentDefinitionNode], root_value: Any, context_value: Any, operation: graphql.language.ast.OperationDefinitionNode, variable_values: Dict[str, Any], field_resolver: Callable[[...], Any], type_resolver: Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]], errors: List[graphql.error.graphql_error.GraphQLError], middleware_manager: Optional[graphql.execution.middleware.MiddlewareManager])

Bases: object

Data that must be available at all points during query execution.

Namely, schema of the type system that is currently executing, and the fragments defined in the query document.

__init__(schema: graphql.type.schema.GraphQLSchema, fragments: Dict[str, graphql.language.ast.FragmentDefinitionNode], root_value: Any, context_value: Any, operation: graphql.language.ast.OperationDefinitionNode, variable_values: Dict[str, Any], field_resolver: Callable[[...], Any], type_resolver: Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]], errors: List[graphql.error.graphql_error.GraphQLError], middleware_manager: Optional[graphql.execution.middleware.MiddlewareManager]) → None

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

classmethod build(schema: graphql.type.schema.GraphQLSchema, document: graphql.language.ast.DocumentNode, root_value: Any = None, context_value: Any = None, raw_variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, field_resolver: Optional[Callable[[...], Any]] = None, type_resolver: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Union[Awaitable[Union[GraphQLObjectType, str, None]], GraphQLObjectType, str, None]]] = None, middleware: Union[Tuple, List, graphql.execution.middleware.MiddlewareManager, None] = None) → Union[List[graphql.error.graphql_error.GraphQLError], graphql.execution.execute.ExecutionContext]

Build an execution context

Constructs a ExecutionContext object from the arguments passed to execute, which we will pass throughout the other execution methods.

Throws a GraphQLError if a valid execution context cannot be created.

For internal use only.

build_resolve_info(field_def: graphql.type.definition.GraphQLField, field_nodes: List[graphql.language.ast.FieldNode], parent_type: graphql.type.definition.GraphQLObjectType, path: graphql.pyutils.path.Path) → graphql.type.definition.GraphQLResolveInfo

Build the GraphQLResolveInfo object.

For internal use only.

build_response(data: Union[Awaitable[Optional[Dict[str, Any]]], Dict[str, Any], None]) → Union[Awaitable[graphql.execution.execute.ExecutionResult], graphql.execution.execute.ExecutionResult]

Build response.

Given a completed execution context and data, build the (data, errors) response defined by the “Response” section of the GraphQL spec.

collect_and_execute_subfields(return_type: graphql.type.definition.GraphQLObjectType, field_nodes: List[graphql.language.ast.FieldNode], path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Collect sub-fields to execute to complete this value.

collect_fields(runtime_type: graphql.type.definition.GraphQLObjectType, selection_set: graphql.language.ast.SelectionSetNode, fields: Dict[str, List[graphql.language.ast.FieldNode]], visited_fragment_names: Set[str]) → Dict[str, List[graphql.language.ast.FieldNode]]

Collect fields.

Given a selection_set, adds all of the fields in that selection to the passed in map of fields, and returns it at the end.

collect_fields requires the “runtime type” of an object. For a field which returns an Interface or Union type, the “runtime type” will be the actual Object type returned by that field.

For internal use only.

collect_subfields(return_type: graphql.type.definition.GraphQLObjectType, field_nodes: List[graphql.language.ast.FieldNode]) → Dict[str, List[graphql.language.ast.FieldNode]]

Collect subfields.

A cached collection of relevant subfields with regard to the return type is kept in the execution context as _subfields_cache. This ensures the subfields are not repeatedly calculated, which saves overhead when resolving lists of values.

complete_abstract_value(return_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Any], Any]

Complete an abstract value.

Complete a value of an abstract type by determining the runtime object type of that value, then complete the value for that type.

static complete_leaf_value(return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType], result: Any) → Any

Complete a leaf value.

Complete a Scalar or Enum by serializing to a valid value, returning null if serialization is not possible.

complete_list_value(return_type: graphql.type.definition.GraphQLList[typing.Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]][Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Iterable[Any]) → Union[Awaitable[Any], Any]

Complete a list value.

Complete a list value by completing each item in the list with the inner type.

complete_object_value(return_type: graphql.type.definition.GraphQLObjectType, field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Complete an Object value by executing all sub-selections.

complete_value(return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Any], Any]

Complete a value.

Implements the instructions for completeValue as defined in the “Field entries” section of the spec.

If the field type is Non-Null, then this recursively completes the value for the inner type. It throws a field error if that completion returns null, as per the “Nullability” section of the spec.

If the field type is a List, then this recursively completes the value for the inner type on each item in the list.

If the field type is a Scalar or Enum, ensures the completed value is a legal value of the type by calling the serialize method of GraphQL type definition.

If the field is an abstract type, determine the runtime type of the value and then complete based on that type.

Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all sub-selections.

complete_value_catching_error(return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, path: graphql.pyutils.path.Path, result: Any) → Union[Awaitable[Any], Any]

Complete a value while catching an error.

This is a small wrapper around completeValue which detects and logs errors in the execution context.

context_value: Any = None
does_fragment_condition_match(fragment: Union[graphql.language.ast.FragmentDefinitionNode, graphql.language.ast.InlineFragmentNode], type_: graphql.type.definition.GraphQLObjectType) → bool

Determine if a fragment is applicable to the given type.

ensure_valid_runtime_type(runtime_type_or_name: Union[graphql.type.definition.GraphQLObjectType, str, None], return_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], field_nodes: List[graphql.language.ast.FieldNode], info: graphql.type.definition.GraphQLResolveInfo, result: Any) → graphql.type.definition.GraphQLObjectType
errors: List[GraphQLError] = None
execute_fields(parent_type: graphql.type.definition.GraphQLObjectType, source_value: Any, path: Optional[graphql.pyutils.path.Path], fields: Dict[str, List[graphql.language.ast.FieldNode]]) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Execute the given fields concurrently.

Implements the “Evaluating selection sets” section of the spec for “read” mode.

execute_fields_serially(parent_type: graphql.type.definition.GraphQLObjectType, source_value: Any, path: Optional[graphql.pyutils.path.Path], fields: Dict[str, List[graphql.language.ast.FieldNode]]) → Union[Awaitable[Dict[str, Any]], Dict[str, Any]]

Execute the given fields serially.

Implements the “Evaluating selection sets” section of the spec for “write” mode.

execute_operation(operation: graphql.language.ast.OperationDefinitionNode, root_value: Any) → Union[Awaitable[Any], Any, None]

Execute an operation.

Implements the “Evaluating operations” section of the spec.

field_resolver: GraphQLFieldResolver = None
fragments: Dict[str, FragmentDefinitionNode] = None
handle_field_error(raw_error: Exception, field_nodes: List[graphql.language.ast.FieldNode], path: graphql.pyutils.path.Path, return_type: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]) → None
middleware_manager: Optional[MiddlewareManager] = None
operation: OperationDefinitionNode = None
resolve_field(parent_type: graphql.type.definition.GraphQLObjectType, source: Any, field_nodes: List[graphql.language.ast.FieldNode], path: graphql.pyutils.path.Path) → Union[Awaitable[Any], Any]

Resolve the field on the given source object.

In particular, this figures out the value that the field returns by calling its resolve function, then calls complete_value to await coroutine objects, serialize scalars, or execute the sub-selection-set for objects.

resolve_field_value_or_error(field_def: graphql.type.definition.GraphQLField, field_nodes: List[graphql.language.ast.FieldNode], resolve_fn: Callable[[...], Any], source: Any, info: graphql.type.definition.GraphQLResolveInfo) → Union[Exception, Any]

Resolve field to a value or an error.

Isolates the “ReturnOrAbrupt” behavior to not de-opt the resolve_field() method. Returns the result of resolveFn or the abrupt-return Error object.

For internal use only.

root_value: Any = None
schema: GraphQLSchema = None
should_include_node(node: Union[graphql.language.ast.FragmentSpreadNode, graphql.language.ast.FieldNode, graphql.language.ast.InlineFragmentNode]) → bool

Check if node should be included

Determines if a field should be included based on the @include and @skip directives, where @skip has higher precedence than @include.

type_resolver: GraphQLTypeResolver = None
variable_values: Dict[str, Any] = None
class graphql.execution.ExecutionResult

Bases: tuple

The result of GraphQL execution.

  • data is the result of a successful execution of the query.

  • errors is included when any errors occurred as a non-empty list.

__init__()

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

_asdict()

Return a new OrderedDict which maps field names to their values.

_field_defaults = {}
_field_types = {'data': typing.Union[typing.Dict[str, typing.Any], NoneType], 'errors': typing.Union[typing.List[graphql.error.graphql_error.GraphQLError], NoneType]}
_fields = ('data', 'errors')
_fields_defaults = {}
classmethod _make(iterable)

Make a new ExecutionResult object from a sequence or iterable

_replace(**kwds)

Return a new ExecutionResult object replacing specified fields with new values

count()

Return number of occurrences of value.

property data

Alias for field number 0

property errors

Alias for field number 1

index()

Return first index of value.

Raises ValueError if the value is not present.

graphql.execution.get_directive_values(directive_def: graphql.type.directives.GraphQLDirective, node: Union[graphql.language.ast.ExecutableDefinitionNode, graphql.language.ast.SelectionNode, graphql.language.ast.SchemaDefinitionNode, graphql.language.ast.TypeDefinitionNode, graphql.language.ast.TypeExtensionNode], variable_values: Optional[Dict[str, Any]] = None) → Optional[Dict[str, Any]]

Get coerced argument values based on provided nodes.

Prepares a dict of argument values given a directive definition and an AST node which may contain directives. Optionally also accepts a dict of variable values.

If the directive does not exist on the node, returns None.