# Reference

GraphQL-core

The primary `graphql` package includes everything you need to define a GraphQL schema and fulfill GraphQL requests.

GraphQL-core provides a reference implementation for the GraphQL specification but is also a useful utility for operating on GraphQL files and building sophisticated tools.

This top-level package exports a general purpose function for fulfilling all steps of the GraphQL specification in a single operation, but also includes utilities for every part of the GraphQL specification:

> - Parsing the GraphQL language.

> - Building a GraphQL type schema.

> - Validating a GraphQL request against a type schema.

> - Executing a GraphQL request against a type schema.

This also includes utility functions for operating on GraphQL types and GraphQL documents to facilitate building tools.

You may also import from each sub-package directly. For example, the following two import statements are equivalent:

    from graphql import parse
    from graphql.language import parse

The sub-packages of GraphQL-core 3 are:

> - `graphql.language`: Parse and operate on the GraphQL language.

> - `graphql.type`: Define GraphQL types and schema.

> - `graphql.validation`: The Validation phase of fulfilling a GraphQL result.

> - `graphql.execution`: The Execution phase of fulfilling a GraphQL request.

> - `graphql.error`: Creating and formatting GraphQL errors.

> - `graphql.utilities`: Common useful computations upon the GraphQL language and type objects.

## Top-Level Functions

async graphql.graphql(schema: GraphQLSchema, source: str | Source, root_value: Any = None, context_value: Any = None, variable_values: Dict[str, Any] | None = None, operation_name: str | None = None, field_resolver: Callable[[...], Any] | None = None, type_resolver: Callable[[Any, GraphQLResolveInfo, GraphQLAbstractType], Awaitable[str | None] | str | None] | None = None, middleware: Tuple | List | MiddlewareManager | None = None, execution_context_class: Type[ExecutionContext] | None = None, is_awaitable: Callable[[Any], bool] | None = None) → ExecutionResult

  Execute a GraphQL operation asynchronously.

  This is the primary entry point function for fulfilling GraphQL operations by parsing, validating, and executing a GraphQL document along side a GraphQL schema.

  More sophisticated GraphQL servers, such as those which persist queries, may wish to separate the validation and execution phases to a static time tooling step, and a server runtime step.

  Accepts the following arguments:

  Parameters:

    - schema – The GraphQL type system to use when validating and executing a query.

    - source – A GraphQL language formatted string representing the requested operation.

    - root_value – The value provided as the first argument to resolver functions on the top level type (e.g. the query object type).

    - context_value – The context value is provided as an attribute of the second argument (the resolve info) to resolver functions. It is used to pass shared information useful at any point during query execution, for example the currently logged in user and connections to databases or other services.

    - variable_values – A mapping of variable name to runtime value to use for all variables defined in the request string.

    - operation_name – The name of the operation to use if request string contains multiple possible operations. Can be omitted if request string contains only one operation.

    - field_resolver – A resolver function to use when one is not provided by the schema. If not provided, the default field resolver is used (which looks for a value or method on the source value with the field’s name).

    - type_resolver – A type resolver function to use when none is provided by the schema. If not provided, the default type resolver is used (which looks for a `__typename` field or alternatively calls the `is_type_of()` method).

    - middleware – The middleware to wrap the resolvers with

    - execution_context_class – The execution context class to use to build the context

    - is_awaitable – The predicate to be used for checking whether values are awaitable

graphql.graphql_sync(schema: GraphQLSchema, source: str | Source, root_value: Any = None, context_value: Any = None, variable_values: Dict[str, Any] | None = None, operation_name: str | None = None, field_resolver: Callable[[...], Any] | None = None, type_resolver: Callable[[Any, GraphQLResolveInfo, GraphQLAbstractType], Awaitable[str | None] | str | None] | None = None, middleware: Tuple | List | MiddlewareManager | None = None, execution_context_class: Type[ExecutionContext] | None = None, check_sync: bool = False) → ExecutionResult

  Execute a GraphQL operation synchronously.

  The graphql_sync function also fulfills GraphQL operations by parsing, validating, and executing a GraphQL document along side a GraphQL schema. However, it guarantees to complete synchronously (or throw an error) assuming that all field resolvers are also synchronous.

  Set check_sync to True to still run checks that no awaitable values are returned.

## Sub-Packages

- Error
  - `GraphQLError`
  - `GraphQLSyntaxError`
  - `GraphQLFormattedError`
  - `located_error()`
- Execution
  - `execute()`
  - `execute_sync()`
  - `default_field_resolver()`
  - `default_type_resolver()`
  - `ExecutionContext`
  - `ExecutionResult`
  - `FormattedExecutionResult`
  - `subscribe()`
  - `create_source_event_stream()`
  - `MapAsyncIterator`
  - `Middleware`
  - `MiddlewareManager`
  - `get_directive_values()`
  - `get_variable_values()`
- Language
  - AST
  - Lexer
  - Location
  - Parser
  - Printer
  - Source
  - Visitor
- PyUtils
  - `camel_to_snake()`
  - `snake_to_camel()`
  - `cached_property()`
  - `register_description()`
  - `unregister_description()`
  - `did_you_mean()`
  - `identity_func()`
  - `inspect()`
  - `is_awaitable()`
  - `is_collection()`
  - `is_iterable()`
  - `natural_comparison_key()`
  - `AwaitableOrValue`
  - `suggestion_list()`
  - `FrozenError`
  - `Path`
  - `print_path_list()`
  - `SimplePubSub`
  - `SimplePubSubIterator`
  - `Undefined`
- Type
  - Definition
  - Directives
  - Introspection
  - Scalars
  - Schema
  - Validate
  - Other
- Utilities
  - `get_introspection_query()`
  - `IntrospectionQuery`
  - `get_operation_ast()`
  - `get_operation_root_type()`
  - `introspection_from_schema()`
  - `build_client_schema()`
  - `build_ast_schema()`
  - `build_schema()`
  - `extend_schema()`
  - `lexicographic_sort_schema()`
  - `print_introspection_schema()`
  - `print_schema()`
  - `print_type()`
  - `type_from_ast()`
  - `ast_to_dict()`
  - `value_from_ast()`
  - `value_from_ast_untyped()`
  - `ast_from_value()`
  - `TypeInfo`
  - `TypeInfoVisitor`
  - `coerce_input_value()`
  - `concat_ast()`
  - `separate_operations()`
  - `strip_ignored_characters()`
  - `is_equal_type()`
  - `is_type_sub_type_of()`
  - `do_types_overlap()`
  - `assert_valid_name()`
  - `is_valid_name_error()`
  - `find_breaking_changes()`
  - `find_dangerous_changes()`
  - `BreakingChange`
  - `BreakingChangeType`
  - `DangerousChange`
  - `DangerousChangeType`
  - `resolve_schema_coordinate()`
  - `resolve_ast_schema_coordinate()`
  - `ResolvedNamedType`
  - `ResolvedField`
  - `ResolvedInputField`
  - `ResolvedEnumValue`
  - `ResolvedFieldArgument`
  - `ResolvedDirective`
  - `ResolvedDirectiveArgument`
  - `ResolvedSchemaElement`
- Validation
  - `validate()`
  - `ASTValidationContext`
  - `ASTValidationRule`
  - `SDLValidationContext`
  - `SDLValidationRule`
  - `ValidationContext`
  - `ValidationRule`
  - Rules