API Reference¶
Schema¶
- class graphene.types.schema.Schema(query=None, mutation=None, subscription=None, directives=None, types=None, auto_camelcase=True)[source]¶
Graphene Schema can execute operations (query, mutation, subscription) against the defined types.
For advanced purposes, the schema can be used to lookup type definitions and answer questions about the types through introspection.
- Parameters
query (ObjectType) – Root query ObjectType. Describes entry point for fields to read data in your Schema.
mutation (ObjectType, optional) – Root mutation ObjectType. Describes entry point for fields to create, update or delete data in your API.
subscription (ObjectType, optional) – Root subscription ObjectType. Describes entry point for fields to receive continuous updates.
directives (List[GraphQLDirective], optional) – List of custom directives to include in GraphQL schema. Defaults to only include directives definved by GraphQL spec (@include and @skip) [GraphQLIncludeDirective, GraphQLSkipDirective].
types (List[GraphQLType], optional) – List of any types to include in schema that may not be introspected through root types.
auto_camelcase (bool) – Fieldnames will be transformed in Schema’s TypeMap from snake_case to camelCase (preferred by GraphQL standard). Default True.
- execute(*args, **kwargs)[source]¶
Use the graphql function from graphql-core to provide the result for a query string. Most of the time this method will be called by one of the Graphene Integrations via a web request.
- Parameters
request_string (str or Document) – GraphQL request (query, mutation or subscription) in string or parsed AST form from graphql-core.
root (Any, optional) – Value to use as the parent value object when resolving root types.
context (Any, optional) – Value to be made avaiable to all resolvers via info.context. Can be used to share authorization, dataloaders or other information needed to resolve an operation.
variables (dict, optional) – If variables are used in the request string, they can be provided in dictionary form mapping the variable name to the variable value.
operation_name (str, optional) – If mutiple operations are provided in the request_string, an operation name must be provided for the result to be provided.
middleware (List[SupportsGraphQLMiddleware]) – Supply request level middleware as defined in graphql-core.
backend (GraphQLCoreBackend, optional) – Override the default GraphQLCoreBackend.
**execute_options (Any) – Depends on backend selected. Default backend has several options such as: validate, allow_subscriptions, return_promise, executor.
- Returns
ExecutionResult
containing any data and errors for the operation.
Object types¶
Fields (Mounted Types)¶
Fields (Unmounted Types)¶
- class graphene.types.unmountedtype.UnmountedType(*args, **kwargs)[source]¶
This class acts a proxy for a Graphene Type, so it can be mounted dynamically as Field, InputField or Argument.
Instead of writing:
from graphene import ObjectType, Field, String class MyObjectType(ObjectType): my_field = Field(String, description='Description here')
It lets you write:
from graphene import ObjectType, String class MyObjectType(ObjectType): my_field = String(description='Description here')
It is not used directly, but is inherited by other types and streamlines their use in different context:
Object Type
Scalar Type
Enum
Interface
Union
An unmounted type will accept arguments based upon its context (ObjectType, Field or InputObjectType) and pass it on to the appropriate MountedType (Field, Argument or InputField).
See each Mounted type reference for more information about valid parameters.
GraphQL Scalars¶
Graphene Scalars¶
Enum¶
Structures¶
Type Extension¶
Execution Metadata¶
- class graphql.execution.base.ExecutionResult(data: Optional[Dict] = None, errors: Optional[List[Exception]] = None, invalid: bool = False, extensions: Optional[Any] = None)[source]¶
The result of execution. data is the result of executing the query, errors is null if no errors occurred, and is a non-empty array if an error occurred.