Type¶
GraphQL Type System
The graphql.type
package is responsible for defining GraphQL types and schema.
-
graphql.type.
GraphQLAbstractType
¶ alias of Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]
-
class
graphql.type.
GraphQLArgument
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL argument
-
__init__
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
default_value
¶
-
description
¶
-
extensions
¶
-
out_name
¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
¶
-
-
class
graphql.type.
GraphQLArgument
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL argument
-
__init__
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
default_value
¶
-
description
¶
-
extensions
¶
-
out_name
¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
¶
-
-
graphql.type.
GraphQLArgumentMap
¶ alias of Dict[str, GraphQLArgument]
-
graphql.type.
GraphQLCompositeType
¶ alias of Union[graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]
-
class
graphql.type.
GraphQLDirective
(name: str, locations: Collection[graphql.language.directive_locations.DirectiveLocation], args: Optional[Dict[str, graphql.type.definition.GraphQLArgument]] = None, is_repeatable: bool = False, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.DirectiveDefinitionNode] = None)¶ Bases:
object
GraphQL Directive
Directives are used by the GraphQL runtime as a way of modifying execution behavior. Type system creators will usually not create these directly.
-
__init__
(name: str, locations: Collection[graphql.language.directive_locations.DirectiveLocation], args: Optional[Dict[str, graphql.type.definition.GraphQLArgument]] = None, is_repeatable: bool = False, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.DirectiveDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
args
¶
-
ast_node
¶
-
description
¶
-
extensions
¶
-
is_repeatable
¶
-
locations
¶
-
name
¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLEnumType
(name: str, values: Union[Dict[str, GraphQLEnumValue], Dict[str, Any], Type[enum.Enum]], description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.EnumTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Enum Type Definition
Some leaf values of requests and input values are Enums. GraphQL serializes Enum values as strings, however internally Enums can be represented by any kind of type, often integers. They can also be provided as a Python Enum.
Example:
RGBType = GraphQLEnumType('RGB', { 'RED': 0, 'GREEN': 1, 'BLUE': 2 })
Example using a Python Enum:
class RGBEnum(enum.Enum): RED = 0 GREEN = 1 BLUE = 2 RGBType = GraphQLEnumType('RGB', enum.Enum)
Instead of raw values, you can also specify GraphQLEnumValue objects with more detail like description or deprecation information.
Note: If a value is not provided in a definition, the name of the enum value will be used as its internal value when the value is serialized.
-
__init__
(name: str, values: Union[Dict[str, GraphQLEnumValue], Dict[str, Any], Type[enum.Enum]], description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.EnumTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
_value_lookup
¶
-
ast_node
¶
-
extension_ast_nodes
¶
-
parse_literal
(value_node: graphql.language.ast.ValueNode, _variables: Optional[Dict[str, Any]] = None) → Any¶
-
parse_value
(input_value: str) → Any¶
-
serialize
(output_value: Any) → str¶
-
to_kwargs
() → Dict[str, Any]¶
-
values
¶
-
-
class
graphql.type.
GraphQLEnumValue
(value: Any = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumValueDefinitionNode] = None)¶ Bases:
object
-
__init__
(value: Any = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
deprecation_reason
¶
-
description
¶
-
extensions
¶
-
property
is_deprecated
¶
-
to_kwargs
() → Dict[str, Any]¶
-
value
¶
-
-
graphql.type.
GraphQLEnumValueMap
¶ alias of Dict[str, GraphQLEnumValue]
-
class
graphql.type.
GraphQLField
(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], args: Optional[Dict[str, GraphQLArgument]] = None, resolve: Optional[GraphQLFieldResolver] = None, subscribe: Optional[GraphQLFieldResolver] = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.FieldDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL field
-
__init__
(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], args: Optional[Dict[str, GraphQLArgument]] = None, resolve: Optional[GraphQLFieldResolver] = None, subscribe: Optional[GraphQLFieldResolver] = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.FieldDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
args
¶
-
ast_node
¶
-
deprecation_reason
¶
-
description
¶
-
extensions
¶
-
property
is_deprecated
¶
-
resolve
¶
-
subscribe
¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
¶
-
-
graphql.type.
GraphQLFieldMap
¶ alias of Dict[str, graphql.type.definition.GraphQLField]
-
graphql.type.
GraphQLFieldResolver
¶ alias of Callable[[…], Any]
-
class
graphql.type.
GraphQLInputField
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL input field
-
__init__
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
default_value
¶
-
description
¶
-
extensions
¶
-
out_name
¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
¶
-
-
graphql.type.
GraphQLInputFieldMap
¶ alias of Dict[str, GraphQLInputField]
-
class
graphql.type.
GraphQLInputObjectType
(name: str, fields: Union[Callable[], Dict[str, GraphQLInputField]], Dict[str, GraphQLInputField]], description: Optional[str] = None, out_type: Optional[Callable[[Dict[str, Any]], Any]] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InputObjectTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Input Object Type Definition
An input object defines a structured collection of fields which may be supplied to a field argument.
Using
NonNull
will ensure that a value must be provided by the query.Example:
NonNullFloat = GraphQLNonNull(GraphQLFloat()) class GeoPoint(GraphQLInputObjectType): name = 'GeoPoint' fields = { 'lat': GraphQLInputField(NonNullFloat), 'lon': GraphQLInputField(NonNullFloat), 'alt': GraphQLInputField( GraphQLFloat(), default_value=0) }
The outbound values will be Python dictionaries by default, but you can have them converted to other types by specifying an
out_type
function or class.-
__init__
(name: str, fields: Union[Callable[], Dict[str, GraphQLInputField]], Dict[str, GraphQLInputField]], description: Optional[str] = None, out_type: Optional[Callable[[Dict[str, Any]], Any]] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InputObjectTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
extension_ast_nodes
¶
-
fields
¶ Get provided fields, wrap them as GraphQLInputField if needed.
-
static
out_type
(value: Dict[str, Any]) → Any¶ Transform outbound values (this is an extension of GraphQL.js).
This default implementation passes values unaltered as dictionaries.
-
to_kwargs
() → Dict[str, Any]¶
-
-
graphql.type.
GraphQLInputType
¶ alias of Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType]
-
graphql.type.
GraphQLInputType
¶ alias of Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType]
-
class
graphql.type.
GraphQLInterfaceType
(name: str, fields: Optional[Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]]] = None, interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InterfaceTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InterfaceTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Interface Type Definition
When a field can return one of a heterogeneous set of types, an Interface type is used to describe what types are possible, what fields are in common across all types, as well as a function to determine which type is actually used when the field is resolved.
Example:
EntityType = GraphQLInterfaceType('Entity', { 'name': GraphQLField(GraphQLString), })
-
__init__
(name: str, fields: Optional[Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]]] = None, interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InterfaceTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InterfaceTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
extension_ast_nodes
¶
-
fields
¶ Get provided fields, wrapping them as GraphQLFields if needed.
-
interfaces
¶ Get provided interfaces.
-
resolve_type
¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
graphql.type.
GraphQLIsTypeOfFn
¶ alias of Callable[[Any, graphql.type.definition.GraphQLResolveInfo], Union[Awaitable[bool], bool]]
-
graphql.type.
GraphQLLeafType
¶ alias of Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType]
-
class
graphql.type.
GraphQLList
(type_: GT)¶ Bases:
graphql.type.definition.GraphQLWrappingType
List Type Wrapper
A list is a wrapping type which points to another type. Lists are often created within the context of defining the fields of an object type.
Example:
class PersonType(GraphQLObjectType): name = 'Person' @property def fields(self): return { 'parents': GraphQLField(GraphQLList(PersonType())), 'children': GraphQLField(GraphQLList(PersonType())), }
-
__init__
(type_: GT)¶ Initialize self. See help(type(self)) for accurate signature.
-
_is_protocol
¶
-
of_type
¶
-
-
class
graphql.type.
GraphQLNamedType
(name: str, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.TypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.TypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLType
Base class for all GraphQL named types
-
__init__
(name: str, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.TypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.TypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
description
¶
-
extension_ast_nodes
¶
-
extensions
¶
-
name
¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLNonNull
(type_: GNT)¶ Bases:
graphql.type.definition.GraphQLWrappingType
,typing.Generic
Non-Null Type Wrapper
A non-null is a wrapping type which points to another type. Non-null types enforce that their values are never null and can ensure an error is raised if this ever occurs during a request. It is useful for fields which you can make a strong guarantee on non-nullability, for example usually the id field of a database row will never be null.
Example:
class RowType(GraphQLObjectType): name = 'Row' fields = { 'id': GraphQLField(GraphQLNonNull(GraphQLString())) }
Note: the enforcement of non-nullability occurs within the executor.
-
__init__
(type_: GNT)¶ Initialize self. See help(type(self)) for accurate signature.
-
_is_protocol
¶
-
of_type
¶
-
-
graphql.type.
GraphQLNullableType
¶ alias of Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLList]
-
class
graphql.type.
GraphQLObjectType
(name: str, fields: Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]], interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, is_type_of: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo], Union[Awaitable[bool], bool]]] = None, extensions: Optional[Dict[str, Any]] = None, description: Optional[str] = None, ast_node: Optional[graphql.language.ast.ObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ObjectTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Object Type Definition
Almost all of the GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.
Example:
AddressType = GraphQLObjectType('Address', { 'street': GraphQLField(GraphQLString), 'number': GraphQLField(GraphQLInt), 'formatted': GraphQLField(GraphQLString, lambda obj, info, **args: f'{obj.number} {obj.street}') })
When two types need to refer to each other, or a type needs to refer to itself in a field, you can use a lambda function with no arguments (a so-called “thunk”) to supply the fields lazily.
Example:
PersonType = GraphQLObjectType('Person', lambda: { 'name': GraphQLField(GraphQLString), 'bestFriend': GraphQLField(PersonType) })
-
__init__
(name: str, fields: Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]], interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, is_type_of: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo], Union[Awaitable[bool], bool]]] = None, extensions: Optional[Dict[str, Any]] = None, description: Optional[str] = None, ast_node: Optional[graphql.language.ast.ObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ObjectTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
extension_ast_nodes
¶
-
fields
¶ Get provided fields, wrapping them as GraphQLFields if needed.
-
interfaces
¶ Get provided interfaces.
-
is_type_of
¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
graphql.type.
GraphQLOutputType
¶ alias of 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]
-
class
graphql.type.
GraphQLResolveInfo
(field_name: str, field_nodes: List[graphql.language.ast.FieldNode], return_type: GraphQLOutputType, parent_type: GraphQLObjectType, path: graphql.pyutils.path.Path, schema: GraphQLSchema, fragments: Dict[str, graphql.language.ast.FragmentDefinitionNode], root_value: Any, operation: graphql.language.ast.OperationDefinitionNode, variable_values: Dict[str, Any], context: Any, is_awaitable: Callable[[Any], bool])¶ Bases:
tuple
Collection of information passed to the resolvers.
This is always passed as the first argument to the resolvers.
Note that contrary to the JavaScript implementation, the context (commonly used to represent an authenticated user, or request-specific caches) is included here and not passed as an additional argument.
-
__init__
()¶ Initialize self. See help(type(self)) for accurate signature.
-
_asdict
()¶ Return a new dict which maps field names to their values.
-
_field_defaults
¶
-
_fields
¶
-
classmethod
_make
(iterable)¶ Make a new GraphQLResolveInfo object from a sequence or iterable
-
_replace
(**kwds)¶ Return a new GraphQLResolveInfo object replacing specified fields with new values
-
context
¶ Alias for field number 10
-
count
(value, /)¶ Return number of occurrences of value.
-
field_name
¶ Alias for field number 0
-
field_nodes
¶ Alias for field number 1
-
fragments
¶ Alias for field number 6
-
index
(value, start=0, stop=9223372036854775807, /)¶ Return first index of value.
Raises ValueError if the value is not present.
-
is_awaitable
¶ Alias for field number 11
-
operation
¶ Alias for field number 8
-
parent_type
¶ Alias for field number 3
-
path
¶ Alias for field number 4
-
return_type
¶ Alias for field number 2
-
root_value
¶ Alias for field number 7
-
schema
¶ Alias for field number 5
-
variable_values
¶ Alias for field number 9
-
-
class
graphql.type.
GraphQLScalarType
(name: str, serialize: Optional[Callable] = None, parse_value: Optional[Callable] = None, parse_literal: Optional[Callable] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.ScalarTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ScalarTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Scalar Type Definition
The leaf values of any request and input values to arguments are Scalars (or Enums) and are defined with a name and a series of functions used to parse input from ast or variables and to ensure validity.
If a type’s serialize function does not return a value (i.e. it returns
None
), then no error will be included in the response.Example:
def serialize_odd(value): if value % 2 == 1: return value odd_type = GraphQLScalarType('Odd', serialize=serialize_odd)
-
__init__
(name: str, serialize: Optional[Callable] = None, parse_value: Optional[Callable] = None, parse_literal: Optional[Callable] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.ScalarTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ScalarTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
¶
-
extension_ast_nodes
¶
-
parse_literal
(node: graphql.language.ast.ValueNode, _variables: Optional[Dict[str, Any]] = None) → Any¶ Parses an externally provided literal value to use as an input.
This default method uses the parse_value method and should be replaced with a more specific version when creating a scalar type.
-
static
parse_value
(value: Any) → Any¶ Parses an externally provided value to use as an input.
This default method just passes the value through and should be replaced with a more specific version when creating a scalar type.
-
static
serialize
(value: Any) → Any¶ Serializes an internal value to include in a response.
This default method just passes the value through and should be replaced with a more specific version when creating a scalar type.
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLSchema
(query: Optional[graphql.type.definition.GraphQLObjectType] = None, mutation: Optional[graphql.type.definition.GraphQLObjectType] = None, subscription: Optional[graphql.type.definition.GraphQLObjectType] = None, types: Optional[Collection[graphql.type.definition.GraphQLNamedType]] = None, directives: Optional[Collection[graphql.type.directives.GraphQLDirective]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.SchemaDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.SchemaExtensionNode]] = None, assume_valid: bool = False)¶ Bases:
object
Schema Definition
A Schema is created by supplying the root types of each type of operation, query and mutation (optional). A schema definition is then supplied to the validator and executor.
Example:
MyAppSchema = GraphQLSchema( query=MyAppQueryRootType, mutation=MyAppMutationRootType)
Note: When the schema is constructed, by default only the types that are reachable by traversing the root types are included, other types must be explicitly referenced.
Example:
character_interface = GraphQLInterfaceType('Character', ...) human_type = GraphQLObjectType( 'Human', interfaces=[character_interface], ...) droid_type = GraphQLObjectType( 'Droid', interfaces: [character_interface], ...) schema = GraphQLSchema( query=GraphQLObjectType('Query', fields={'hero': GraphQLField(character_interface, ....)}), ... # Since this schema references only the `Character` interface it's # necessary to explicitly list the types that implement it if # you want them to be included in the final schema. types=[human_type, droid_type])
Note: If a list of
directives
is provided to GraphQLSchema, that will be the exact list of directives represented and allowed. Ifdirectives
is not provided, then a default set of the specified directives (e.g. @include and @skip) will be used. If you wish to provide additional directives to these specified directives, you must explicitly declare them. Example:MyAppSchema = GraphQLSchema( ... directives=specified_directives + [my_custom_directive])
-
__init__
(query: Optional[graphql.type.definition.GraphQLObjectType] = None, mutation: Optional[graphql.type.definition.GraphQLObjectType] = None, subscription: Optional[graphql.type.definition.GraphQLObjectType] = None, types: Optional[Collection[graphql.type.definition.GraphQLNamedType]] = None, directives: Optional[Collection[graphql.type.directives.GraphQLDirective]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.SchemaDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.SchemaExtensionNode]] = None, assume_valid: bool = False) → None¶ Initialize GraphQL schema.
If this schema was built from a source known to be valid, then it may be marked with
assume_valid
to avoid an additional type system validation.
-
_implementations_map
¶
-
_sub_type_map
¶
-
_validation_errors
¶
-
ast_node
¶
-
description
¶
-
directives
¶
-
extension_ast_nodes
¶
-
extensions
¶
-
get_directive
(name: str) → Optional[graphql.type.directives.GraphQLDirective]¶
-
get_implementations
(interface_type: graphql.type.definition.GraphQLInterfaceType) → graphql.type.schema.InterfaceImplementations¶
-
get_possible_types
(abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]) → List[graphql.type.definition.GraphQLObjectType]¶ Get list of all possible concrete types for given abstract type.
-
get_type
(name: str) → Optional[graphql.type.definition.GraphQLNamedType]¶
-
is_possible_type
(abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], possible_type: graphql.type.definition.GraphQLObjectType) → bool¶ Check whether a concrete type is possible for an abstract type.
Deprecated: Use is_sub_type() instead.
-
is_sub_type
(abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], maybe_sub_type: Union[graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType]) → bool¶ Check whether a type is a subtype of a given abstract type.
-
mutation_type
¶
-
query_type
¶
-
subscription_type
¶
-
to_kwargs
() → Dict[str, Any]¶
-
type_map
¶
-
property
validation_errors
¶
-
-
class
graphql.type.
GraphQLType
¶ Bases:
object
Base class for all GraphQL types
-
__init__
()¶ Initialize self. See help(type(self)) for accurate signature.
-
-
graphql.type.
GraphQLTypeResolver
¶ alias of Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]
-
class
graphql.type.
GraphQLUnionType
(name, types: Union[Callable[], Collection[graphql.type.definition.GraphQLObjectType]], Collection[graphql.type.definition.GraphQLObjectType]], resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.UnionTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.UnionTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Union Type Definition
When a field can return one of a heterogeneous set of types, a Union type is used to describe what types are possible as well as providing a function to determine which type is actually used when the field is resolved.
Example:
class PetType(GraphQLUnionType): name = 'Pet' types = [DogType, CatType] def resolve_type(self, value, _type): if isinstance(value, Dog): return DogType() if isinstance(value, Cat): return CatType()
-
__init__
(name, types: Union[Callable[], Collection[graphql.type.definition.GraphQLObjectType]], Collection[graphql.type.definition.GraphQLObjectType]], resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.UnionTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.UnionTypeExtensionNode]] = None) → None¶ - Return type
object
-
ast_node
¶
-
extension_ast_nodes
¶
-
resolve_type
¶
-
to_kwargs
() → Dict[str, Any]¶
-
types
¶ Get provided types.
-
-
class
graphql.type.
GraphQLWrappingType
(type_: GT)¶ Bases:
graphql.type.definition.GraphQLType
,typing.Generic
Base class for all GraphQL wrapping types
-
__init__
(type_: GT)¶ Initialize self. See help(type(self)) for accurate signature.
-
_is_protocol
¶
-
of_type
¶
-
-
graphql.type.
ResponsePath
¶ alias of
graphql.pyutils.path.Path
-
graphql.type.
Thunk
¶ alias of Union[Callable[[], T], T]
-
class
graphql.type.
TypeKind
(value)¶ Bases:
enum.Enum
An enumeration.
-
ENUM
¶
-
INPUT_OBJECT
¶
-
INTERFACE
¶
-
LIST
¶
-
NON_NULL
¶
-
OBJECT
¶
-
SCALAR
¶
-
UNION
¶
-
-
graphql.type.
assert_abstract_type
(type_: Any) → Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]¶
-
graphql.type.
assert_composite_type
(type_: Any) → graphql.type.definition.GraphQLType¶
-
graphql.type.
assert_directive
(directive: Any) → graphql.type.directives.GraphQLDirective¶
-
graphql.type.
assert_enum_type
(type_: Any) → graphql.type.definition.GraphQLEnumType¶
-
graphql.type.
assert_input_object_type
(type_: Any) → graphql.type.definition.GraphQLInputObjectType¶
-
graphql.type.
assert_input_type
(type_: Any) → Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType]¶
-
graphql.type.
assert_interface_type
(type_: Any) → graphql.type.definition.GraphQLInterfaceType¶
-
graphql.type.
assert_leaf_type
(type_: Any) → Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType]¶
-
graphql.type.
assert_list_type
(type_: Any) → graphql.type.definition.GraphQLList¶
-
graphql.type.
assert_named_type
(type_: Any) → graphql.type.definition.GraphQLNamedType¶
-
graphql.type.
assert_non_null_type
(type_: Any) → graphql.type.definition.GraphQLNonNull¶
-
graphql.type.
assert_nullable_type
(type_: Any) → Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLList]¶
-
graphql.type.
assert_object_type
(type_: Any) → graphql.type.definition.GraphQLObjectType¶
-
graphql.type.
assert_output_type
(type_: Any) → 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]¶
-
graphql.type.
assert_scalar_type
(type_: Any) → graphql.type.definition.GraphQLScalarType¶
-
graphql.type.
assert_schema
(schema: Any) → graphql.type.schema.GraphQLSchema¶
-
graphql.type.
assert_type
(type_: Any) → graphql.type.definition.GraphQLType¶
-
graphql.type.
assert_union_type
(type_: Any) → graphql.type.definition.GraphQLUnionType¶
-
graphql.type.
assert_valid_schema
(schema: graphql.type.schema.GraphQLSchema) → None¶ Utility function which asserts a schema is valid.
Throws a TypeError if the schema is invalid.
-
graphql.type.
assert_wrapping_type
(type_: Any) → graphql.type.definition.GraphQLWrappingType¶
-
graphql.type.
get_named_type
(type_)¶ Unwrap possible wrapping type
-
graphql.type.
get_nullable_type
(type_)¶ Unwrap possible non-null type
-
graphql.type.
is_abstract_type
(type_: Any) → bool¶
-
graphql.type.
is_composite_type
(type_: Any) → bool¶
-
graphql.type.
is_directive
(directive: Any) → bool¶ Test if the given value is a GraphQL directive.
-
graphql.type.
is_enum_type
(type_: Any) → bool¶
-
graphql.type.
is_input_object_type
(type_: Any) → bool¶
-
graphql.type.
is_input_type
(type_: Any) → bool¶
-
graphql.type.
is_interface_type
(type_: Any) → bool¶
-
graphql.type.
is_introspection_type
(type_: graphql.type.definition.GraphQLNamedType) → bool¶ Check whether the given named GraphQL type is an introspection type.
-
graphql.type.
is_leaf_type
(type_: Any) → bool¶
-
graphql.type.
is_list_type
(type_: Any) → bool¶
-
graphql.type.
is_named_type
(type_: Any) → bool¶
-
graphql.type.
is_non_null_type
(type_: Any) → bool¶
-
graphql.type.
is_nullable_type
(type_: Any) → bool¶
-
graphql.type.
is_object_type
(type_: Any) → bool¶
-
graphql.type.
is_output_type
(type_: Any) → bool¶
-
graphql.type.
is_required_argument
(arg: graphql.type.definition.GraphQLArgument) → bool¶
-
graphql.type.
is_required_input_field
(field: graphql.type.definition.GraphQLInputField) → bool¶
-
graphql.type.
is_scalar_type
(type_: Any) → bool¶
-
graphql.type.
is_schema
(schema: Any) → bool¶ Test if the given value is a GraphQL schema.
-
graphql.type.
is_specified_directive
(directive: graphql.type.directives.GraphQLDirective) → bool¶ Check whether the given directive is one of the specified directives.
-
graphql.type.
is_specified_scalar_type
(type_: graphql.type.definition.GraphQLNamedType) → bool¶ Check whether the given named GraphQL type is a specified scalar type.
-
graphql.type.
is_type
(type_: Any) → bool¶
-
graphql.type.
is_union_type
(type_: Any) → bool¶
-
graphql.type.
is_wrapping_type
(type_: Any) → bool¶
-
graphql.type.
validate_schema
(schema: graphql.type.schema.GraphQLSchema) → List[graphql.error.graphql_error.GraphQLError]¶ Validate a GraphQL schema.
Implements the “Type Validation” sub-sections of the specification’s “Type System” section.
Validation runs synchronously, returning a list of encountered errors, or an empty list if no errors were encountered and the Schema is valid.
Definition¶
Predicates¶
-
graphql.type.
is_composite_type
(type_: Any) → bool¶
-
graphql.type.
is_enum_type
(type_: Any) → bool¶
-
graphql.type.
is_input_object_type
(type_: Any) → bool¶
-
graphql.type.
is_input_type
(type_: Any) → bool¶
-
graphql.type.
is_interface_type
(type_: Any) → bool¶
-
graphql.type.
is_leaf_type
(type_: Any) → bool¶
-
graphql.type.
is_list_type
(type_: Any) → bool¶
-
graphql.type.
is_named_type
(type_: Any) → bool¶
-
graphql.type.
is_non_null_type
(type_: Any) → bool¶
-
graphql.type.
is_nullable_type
(type_: Any) → bool¶
-
graphql.type.
is_object_type
(type_: Any) → bool¶
-
graphql.type.
is_output_type
(type_: Any) → bool¶
-
graphql.type.
is_scalar_type
(type_: Any) → bool¶
-
graphql.type.
is_type
(type_: Any) → bool¶
-
graphql.type.
is_union_type
(type_: Any) → bool¶
-
graphql.type.
is_wrapping_type
(type_: Any) → bool¶
Assertions¶
-
graphql.type.
assert_abstract_type
(type_: Any) → Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]¶
-
graphql.type.
assert_composite_type
(type_: Any) → graphql.type.definition.GraphQLType¶
-
graphql.type.
assert_enum_type
(type_: Any) → graphql.type.definition.GraphQLEnumType¶
-
graphql.type.
assert_input_object_type
(type_: Any) → graphql.type.definition.GraphQLInputObjectType¶
-
graphql.type.
assert_input_type
(type_: Any) → Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType]¶
-
graphql.type.
assert_interface_type
(type_: Any) → graphql.type.definition.GraphQLInterfaceType¶
-
graphql.type.
assert_leaf_type
(type_: Any) → Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType]¶
-
graphql.type.
assert_list_type
(type_: Any) → graphql.type.definition.GraphQLList¶
-
graphql.type.
assert_named_type
(type_: Any) → graphql.type.definition.GraphQLNamedType¶
-
graphql.type.
assert_non_null_type
(type_: Any) → graphql.type.definition.GraphQLNonNull¶
-
graphql.type.
assert_nullable_type
(type_: Any) → Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLList]¶
-
graphql.type.
assert_object_type
(type_: Any) → graphql.type.definition.GraphQLObjectType¶
-
graphql.type.
assert_output_type
(type_: Any) → 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]¶
-
graphql.type.
assert_scalar_type
(type_: Any) → graphql.type.definition.GraphQLScalarType¶
-
graphql.type.
assert_type
(type_: Any) → graphql.type.definition.GraphQLType¶
-
graphql.type.
assert_union_type
(type_: Any) → graphql.type.definition.GraphQLUnionType¶
-
graphql.type.
assert_wrapping_type
(type_: Any) → graphql.type.definition.GraphQLWrappingType¶
Un-modifiers¶
-
graphql.type.
get_nullable_type
(type_: None) → None¶ -
graphql.type.
get_nullable_type
(type_: GraphQLNullableType) → GraphQLNullableType -
graphql.type.
get_nullable_type
(type_: GraphQLNonNull) → GraphQLNullableType Unwrap possible non-null type
-
graphql.type.
get_named_type
(type_: None) → None¶ -
graphql.type.
get_named_type
(type_: GraphQLType) → GraphQLNamedType Unwrap possible wrapping type
Definitions¶
-
class
graphql.type.
GraphQLEnumType
(name: str, values: Union[Dict[str, GraphQLEnumValue], Dict[str, Any], Type[enum.Enum]], description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.EnumTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Enum Type Definition
Some leaf values of requests and input values are Enums. GraphQL serializes Enum values as strings, however internally Enums can be represented by any kind of type, often integers. They can also be provided as a Python Enum.
Example:
RGBType = GraphQLEnumType('RGB', { 'RED': 0, 'GREEN': 1, 'BLUE': 2 })
Example using a Python Enum:
class RGBEnum(enum.Enum): RED = 0 GREEN = 1 BLUE = 2 RGBType = GraphQLEnumType('RGB', enum.Enum)
Instead of raw values, you can also specify GraphQLEnumValue objects with more detail like description or deprecation information.
Note: If a value is not provided in a definition, the name of the enum value will be used as its internal value when the value is serialized.
-
__init__
(name: str, values: Union[Dict[str, GraphQLEnumValue], Dict[str, Any], Type[enum.Enum]], description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.EnumTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
_value_lookup
¶
-
ast_node
: Optional[EnumTypeDefinitionNode]¶
-
extension_ast_nodes
: Optional[FrozenList[EnumTypeExtensionNode]]¶
-
parse_literal
(value_node: graphql.language.ast.ValueNode, _variables: Optional[Dict[str, Any]] = None) → Any¶
-
parse_value
(input_value: str) → Any¶
-
serialize
(output_value: Any) → str¶
-
to_kwargs
() → Dict[str, Any]¶
-
values
: GraphQLEnumValueMap¶
-
-
class
graphql.type.
GraphQLInputObjectType
(name: str, fields: Union[Callable[], Dict[str, GraphQLInputField]], Dict[str, GraphQLInputField]], description: Optional[str] = None, out_type: Optional[Callable[[Dict[str, Any]], Any]] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InputObjectTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Input Object Type Definition
An input object defines a structured collection of fields which may be supplied to a field argument.
Using
NonNull
will ensure that a value must be provided by the query.Example:
NonNullFloat = GraphQLNonNull(GraphQLFloat()) class GeoPoint(GraphQLInputObjectType): name = 'GeoPoint' fields = { 'lat': GraphQLInputField(NonNullFloat), 'lon': GraphQLInputField(NonNullFloat), 'alt': GraphQLInputField( GraphQLFloat(), default_value=0) }
The outbound values will be Python dictionaries by default, but you can have them converted to other types by specifying an
out_type
function or class.-
__init__
(name: str, fields: Union[Callable[], Dict[str, GraphQLInputField]], Dict[str, GraphQLInputField]], description: Optional[str] = None, out_type: Optional[Callable[[Dict[str, Any]], Any]] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InputObjectTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[InputObjectTypeDefinitionNode]¶
-
extension_ast_nodes
: Optional[FrozenList[InputObjectTypeExtensionNode]]¶
-
fields
¶ Get provided fields, wrap them as GraphQLInputField if needed.
-
static
out_type
(value: Dict[str, Any]) → Any¶ Transform outbound values (this is an extension of GraphQL.js).
This default implementation passes values unaltered as dictionaries.
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLInterfaceType
(name: str, fields: Optional[Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]]] = None, interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InterfaceTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InterfaceTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Interface Type Definition
When a field can return one of a heterogeneous set of types, an Interface type is used to describe what types are possible, what fields are in common across all types, as well as a function to determine which type is actually used when the field is resolved.
Example:
EntityType = GraphQLInterfaceType('Entity', { 'name': GraphQLField(GraphQLString), })
-
__init__
(name: str, fields: Optional[Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]]] = None, interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InterfaceTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.InterfaceTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[InterfaceTypeDefinitionNode]¶
-
extension_ast_nodes
: Optional[FrozenList[InterfaceTypeExtensionNode]]¶
-
fields
¶ Get provided fields, wrapping them as GraphQLFields if needed.
-
interfaces
¶ Get provided interfaces.
-
resolve_type
: Optional[GraphQLTypeResolver]¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLObjectType
(name: str, fields: Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]], interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, is_type_of: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo], Union[Awaitable[bool], bool]]] = None, extensions: Optional[Dict[str, Any]] = None, description: Optional[str] = None, ast_node: Optional[graphql.language.ast.ObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ObjectTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Object Type Definition
Almost all of the GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.
Example:
AddressType = GraphQLObjectType('Address', { 'street': GraphQLField(GraphQLString), 'number': GraphQLField(GraphQLInt), 'formatted': GraphQLField(GraphQLString, lambda obj, info, **args: f'{obj.number} {obj.street}') })
When two types need to refer to each other, or a type needs to refer to itself in a field, you can use a lambda function with no arguments (a so-called “thunk”) to supply the fields lazily.
Example:
PersonType = GraphQLObjectType('Person', lambda: { 'name': GraphQLField(GraphQLString), 'bestFriend': GraphQLField(PersonType) })
-
__init__
(name: str, fields: Union[Callable[], Dict[str, graphql.type.definition.GraphQLField]], Dict[str, graphql.type.definition.GraphQLField]], interfaces: Optional[Union[Callable[], Collection[GraphQLInterfaceType]], Collection[GraphQLInterfaceType]]] = None, is_type_of: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo], Union[Awaitable[bool], bool]]] = None, extensions: Optional[Dict[str, Any]] = None, description: Optional[str] = None, ast_node: Optional[graphql.language.ast.ObjectTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ObjectTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[ObjectTypeDefinitionNode]¶
-
extension_ast_nodes
: Optional[FrozenList[ObjectTypeExtensionNode]]¶
-
fields
¶ Get provided fields, wrapping them as GraphQLFields if needed.
-
interfaces
¶ Get provided interfaces.
-
is_type_of
: Optional[GraphQLIsTypeOfFn]¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLScalarType
(name: str, serialize: Optional[Callable] = None, parse_value: Optional[Callable] = None, parse_literal: Optional[Callable] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.ScalarTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ScalarTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Scalar Type Definition
The leaf values of any request and input values to arguments are Scalars (or Enums) and are defined with a name and a series of functions used to parse input from ast or variables and to ensure validity.
If a type’s serialize function does not return a value (i.e. it returns
None
), then no error will be included in the response.Example:
def serialize_odd(value): if value % 2 == 1: return value odd_type = GraphQLScalarType('Odd', serialize=serialize_odd)
-
__init__
(name: str, serialize: Optional[Callable] = None, parse_value: Optional[Callable] = None, parse_literal: Optional[Callable] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.ScalarTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.ScalarTypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[ScalarTypeDefinitionNode]¶
-
extension_ast_nodes
: Optional[FrozenList[ScalarTypeExtensionNode]]¶
-
parse_literal
(node: graphql.language.ast.ValueNode, _variables: Optional[Dict[str, Any]] = None) → Any¶ Parses an externally provided literal value to use as an input.
This default method uses the parse_value method and should be replaced with a more specific version when creating a scalar type.
-
static
parse_value
(value: Any) → Any¶ Parses an externally provided value to use as an input.
This default method just passes the value through and should be replaced with a more specific version when creating a scalar type.
-
static
serialize
(value: Any) → Any¶ Serializes an internal value to include in a response.
This default method just passes the value through and should be replaced with a more specific version when creating a scalar type.
-
to_kwargs
() → Dict[str, Any]¶
-
-
class
graphql.type.
GraphQLUnionType
(name, types: Union[Callable[], Collection[graphql.type.definition.GraphQLObjectType]], Collection[graphql.type.definition.GraphQLObjectType]], resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.UnionTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.UnionTypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLNamedType
Union Type Definition
When a field can return one of a heterogeneous set of types, a Union type is used to describe what types are possible as well as providing a function to determine which type is actually used when the field is resolved.
Example:
class PetType(GraphQLUnionType): name = 'Pet' types = [DogType, CatType] def resolve_type(self, value, _type): if isinstance(value, Dog): return DogType() if isinstance(value, Cat): return CatType()
-
__init__
(name, types: Union[Callable[], Collection[graphql.type.definition.GraphQLObjectType]], Collection[graphql.type.definition.GraphQLObjectType]], resolve_type: Optional[Callable[[Any, graphql.type.definition.GraphQLResolveInfo, GraphQLAbstractType], Optional[Union[Awaitable[Optional[Union[GraphQLObjectType, str]]], GraphQLObjectType, str]]]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.UnionTypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.UnionTypeExtensionNode]] = None) → None¶ - Return type
object
-
ast_node
: Optional[UnionTypeDefinitionNode]¶
-
extension_ast_nodes
: Optional[FrozenList[UnionTypeExtensionNode]]¶
-
resolve_type
: Optional[GraphQLTypeResolver]¶
-
to_kwargs
() → Dict[str, Any]¶
-
types
¶ Get provided types.
-
Type Wrappers¶
-
class
graphql.type.
GraphQLList
(type_: GT)¶ Bases:
graphql.type.definition.GraphQLWrappingType
List Type Wrapper
A list is a wrapping type which points to another type. Lists are often created within the context of defining the fields of an object type.
Example:
class PersonType(GraphQLObjectType): name = 'Person' @property def fields(self): return { 'parents': GraphQLField(GraphQLList(PersonType())), 'children': GraphQLField(GraphQLList(PersonType())), }
-
__init__
(type_: GT)¶ Initialize self. See help(type(self)) for accurate signature.
-
_is_protocol
= False¶
-
of_type
¶
-
-
class
graphql.type.
GraphQLNonNull
(type_: GNT)¶ Bases:
graphql.type.definition.GraphQLWrappingType
,typing.Generic
Non-Null Type Wrapper
A non-null is a wrapping type which points to another type. Non-null types enforce that their values are never null and can ensure an error is raised if this ever occurs during a request. It is useful for fields which you can make a strong guarantee on non-nullability, for example usually the id field of a database row will never be null.
Example:
class RowType(GraphQLObjectType): name = 'Row' fields = { 'id': GraphQLField(GraphQLNonNull(GraphQLString())) }
Note: the enforcement of non-nullability occurs within the executor.
-
__init__
(type_: GNT)¶ Initialize self. See help(type(self)) for accurate signature.
-
_is_protocol
= False¶
-
of_type
¶
-
Types¶
-
graphql.type.
GraphQLAbstractType
¶
-
class
graphql.type.
GraphQLArgument
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL argument
-
__init__
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[InputValueDefinitionNode]¶
-
default_value
: Any¶
-
description
: Optional[str]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
out_name
: Optional[str]¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
: ‘GraphQLInputType’¶
-
-
graphql.type.
GraphQLArgumentMap
¶
-
graphql.type.
GraphQLCompositeType
¶
-
class
graphql.type.
GraphQLEnumValue
(value: Any = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumValueDefinitionNode] = None)¶ Bases:
object
-
__init__
(value: Any = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.EnumValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[EnumValueDefinitionNode]¶
-
deprecation_reason
: Optional[str]¶
-
description
: Optional[str]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
property
is_deprecated
¶
-
to_kwargs
() → Dict[str, Any]¶
-
value
: Any¶
-
-
graphql.type.
GraphQLEnumValueMap
¶
-
class
graphql.type.
GraphQLField
(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], args: Optional[Dict[str, GraphQLArgument]] = None, resolve: Optional[GraphQLFieldResolver] = None, subscribe: Optional[GraphQLFieldResolver] = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.FieldDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL field
-
__init__
(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], args: Optional[Dict[str, GraphQLArgument]] = None, resolve: Optional[GraphQLFieldResolver] = None, subscribe: Optional[GraphQLFieldResolver] = None, description: Optional[str] = None, deprecation_reason: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.FieldDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
args
: GraphQLArgumentMap¶
-
ast_node
: Optional[FieldDefinitionNode]¶
-
deprecation_reason
: Optional[str]¶
-
description
: Optional[str]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
property
is_deprecated
¶
-
resolve
: Optional[‘GraphQLFieldResolver’]¶
-
subscribe
: Optional[‘GraphQLFieldResolver’]¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
: ‘GraphQLOutputType’¶
-
-
graphql.type.
GraphQLFieldMap
¶
-
class
graphql.type.
GraphQLInputField
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None)¶ Bases:
object
Definition of a GraphQL input field
-
__init__
(type_: Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType], default_value: Any = Undefined, description: Optional[str] = None, out_name: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.InputValueDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[InputValueDefinitionNode]¶
-
default_value
: Any¶
-
description
: Optional[str]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
out_name
: Optional[str]¶
-
to_kwargs
() → Dict[str, Any]¶
-
type
: ‘GraphQLInputType’¶
-
-
graphql.type.
GraphQLInputFieldMap
¶
-
graphql.type.
GraphQLInputType
¶
-
graphql.type.
GraphQLLeafType
¶
-
class
graphql.type.
GraphQLNamedType
(name: str, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.TypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.TypeExtensionNode]] = None)¶ Bases:
graphql.type.definition.GraphQLType
Base class for all GraphQL named types
-
__init__
(name: str, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.TypeDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.TypeExtensionNode]] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
ast_node
: Optional[TypeDefinitionNode]¶
-
description
: Optional[str]¶
-
extension_ast_nodes
: Optional[FrozenList[TypeExtensionNode]]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
name
: str¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
graphql.type.
GraphQLNullableType
¶
-
graphql.type.
GraphQLOutputType
¶
-
class
graphql.type.
GraphQLType
¶ Bases:
object
Base class for all GraphQL types
-
__init__
()¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
graphql.type.
GraphQLWrappingType
(type_: GT)¶ Bases:
graphql.type.definition.GraphQLType
,typing.Generic
Base class for all GraphQL wrapping types
-
__init__
(type_: GT)¶ Initialize self. See help(type(self)) for accurate signature.
-
_is_protocol
= False¶
-
of_type
: GT¶
-
-
graphql.type.
Thunk
¶
Resolvers¶
-
graphql.type.
GraphQLFieldResolver
¶
-
graphql.type.
GraphQLIsTypeOfFn
¶
-
class
graphql.type.
GraphQLResolveInfo
(field_name: str, field_nodes: List[graphql.language.ast.FieldNode], return_type: GraphQLOutputType, parent_type: GraphQLObjectType, path: graphql.pyutils.path.Path, schema: GraphQLSchema, fragments: Dict[str, graphql.language.ast.FragmentDefinitionNode], root_value: Any, operation: graphql.language.ast.OperationDefinitionNode, variable_values: Dict[str, Any], context: Any, is_awaitable: Callable[[Any], bool])¶ Bases:
tuple
Collection of information passed to the resolvers.
This is always passed as the first argument to the resolvers.
Note that contrary to the JavaScript implementation, the context (commonly used to represent an authenticated user, or request-specific caches) is included here and not passed as an additional argument.
-
__init__
()¶ Initialize self. See help(type(self)) for accurate signature.
-
_asdict
()¶ Return a new dict which maps field names to their values.
-
_field_defaults
= {}¶
-
_fields
= ('field_name', 'field_nodes', 'return_type', 'parent_type', 'path', 'schema', 'fragments', 'root_value', 'operation', 'variable_values', 'context', 'is_awaitable')¶
-
classmethod
_make
(iterable)¶ Make a new GraphQLResolveInfo object from a sequence or iterable
-
_replace
(**kwds)¶ Return a new GraphQLResolveInfo object replacing specified fields with new values
-
context
: Any¶ Alias for field number 10
-
count
(value, /)¶ Return number of occurrences of value.
-
field_name
: str¶ Alias for field number 0
-
field_nodes
: List[graphql.language.ast.FieldNode]¶ Alias for field number 1
-
fragments
: Dict[str, graphql.language.ast.FragmentDefinitionNode]¶ Alias for field number 6
-
index
(value, start=0, stop=9223372036854775807, /)¶ Return first index of value.
Raises ValueError if the value is not present.
-
is_awaitable
: Callable[[Any], bool]¶ Alias for field number 11
-
operation
: graphql.language.ast.OperationDefinitionNode¶ Alias for field number 8
-
parent_type
: GraphQLObjectType¶ Alias for field number 3
-
path
: graphql.pyutils.path.Path¶ Alias for field number 4
-
return_type
: GraphQLOutputType¶ Alias for field number 2
-
root_value
: Any¶ Alias for field number 7
-
schema
: GraphQLSchema¶ Alias for field number 5
-
variable_values
: Dict[str, Any]¶ Alias for field number 9
-
-
graphql.type.
GraphQLTypeResolver
¶
Directives¶
Predicates¶
-
graphql.type.
is_directive
(directive: Any) → bool¶ Test if the given value is a GraphQL directive.
-
graphql.type.
is_specified_directive
(directive: graphql.type.directives.GraphQLDirective) → bool¶ Check whether the given directive is one of the specified directives.
Definitions¶
-
class
graphql.type.
GraphQLDirective
(name: str, locations: Collection[graphql.language.directive_locations.DirectiveLocation], args: Optional[Dict[str, graphql.type.definition.GraphQLArgument]] = None, is_repeatable: bool = False, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.DirectiveDefinitionNode] = None)¶ Bases:
object
GraphQL Directive
Directives are used by the GraphQL runtime as a way of modifying execution behavior. Type system creators will usually not create these directly.
-
__init__
(name: str, locations: Collection[graphql.language.directive_locations.DirectiveLocation], args: Optional[Dict[str, graphql.type.definition.GraphQLArgument]] = None, is_repeatable: bool = False, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.DirectiveDefinitionNode] = None) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
args
: Dict[str, GraphQLArgument]¶
-
ast_node
: Optional[ast.DirectiveDefinitionNode]¶
-
description
: Optional[str]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
is_repeatable
: bool¶
-
locations
: List[DirectiveLocation]¶
-
name
: str¶
-
to_kwargs
() → Dict[str, Any]¶
-
-
graphql.type.
GraphQLIncludeDirective
¶
-
graphql.type.
GraphQLSkipDirective
¶
-
graphql.type.
GraphQLDeprecatedDirective
¶
-
graphql.type.
specified_directives
= [<GraphQLDirective(@include)>, <GraphQLDirective(@skip)>, <GraphQLDirective(@deprecated)>]¶ The full list of specified directives.
-
graphql.type.
DEFAULT_DEPRECATION_REASON
= 'No longer supported'¶ String constant that can be used as the default value for
deprecation_reason
.
Introspection¶
Predicates¶
-
graphql.type.
is_introspection_type
(type_: graphql.type.definition.GraphQLNamedType) → bool¶ Check whether the given named GraphQL type is an introspection type.
Definitions¶
-
class
graphql.type.
TypeKind
(value)¶ Bases:
enum.Enum
An enumeration.
-
ENUM
= 'enum'¶
-
INPUT_OBJECT
= 'input object'¶
-
INTERFACE
= 'interface'¶
-
LIST
= 'list'¶
-
NON_NULL
= 'non-null'¶
-
OBJECT
= 'object'¶
-
SCALAR
= 'scalar'¶
-
UNION
= 'union'¶
-
-
graphql.type.
TypeMetaFieldDef
¶
-
graphql.type.
TypeNameMetaFieldDef
¶
-
graphql.type.
SchemaMetaFieldDef
¶
-
graphql.type.
introspection_types
= {'__Directive': <GraphQLObjectType '__Directive'>, '__DirectiveLocation': <GraphQLEnumType '__DirectiveLocation'>, '__EnumValue': <GraphQLObjectType '__EnumValue'>, '__Field': <GraphQLObjectType '__Field'>, '__InputValue': <GraphQLObjectType '__InputValue'>, '__Schema': <GraphQLObjectType '__Schema'>, '__Type': <GraphQLObjectType '__Type'>, '__TypeKind': <GraphQLEnumType '__TypeKind'>}¶ A dictionary containing all introspection types.
Scalars¶
Schema¶
Predicates¶
-
graphql.type.
is_schema
(schema: Any) → bool¶ Test if the given value is a GraphQL schema.
Definitions¶
-
class
graphql.type.
GraphQLSchema
(query: Optional[graphql.type.definition.GraphQLObjectType] = None, mutation: Optional[graphql.type.definition.GraphQLObjectType] = None, subscription: Optional[graphql.type.definition.GraphQLObjectType] = None, types: Optional[Collection[graphql.type.definition.GraphQLNamedType]] = None, directives: Optional[Collection[graphql.type.directives.GraphQLDirective]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.SchemaDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.SchemaExtensionNode]] = None, assume_valid: bool = False)¶ Bases:
object
Schema Definition
A Schema is created by supplying the root types of each type of operation, query and mutation (optional). A schema definition is then supplied to the validator and executor.
Example:
MyAppSchema = GraphQLSchema( query=MyAppQueryRootType, mutation=MyAppMutationRootType)
Note: When the schema is constructed, by default only the types that are reachable by traversing the root types are included, other types must be explicitly referenced.
Example:
character_interface = GraphQLInterfaceType('Character', ...) human_type = GraphQLObjectType( 'Human', interfaces=[character_interface], ...) droid_type = GraphQLObjectType( 'Droid', interfaces: [character_interface], ...) schema = GraphQLSchema( query=GraphQLObjectType('Query', fields={'hero': GraphQLField(character_interface, ....)}), ... # Since this schema references only the `Character` interface it's # necessary to explicitly list the types that implement it if # you want them to be included in the final schema. types=[human_type, droid_type])
Note: If a list of
directives
is provided to GraphQLSchema, that will be the exact list of directives represented and allowed. Ifdirectives
is not provided, then a default set of the specified directives (e.g. @include and @skip) will be used. If you wish to provide additional directives to these specified directives, you must explicitly declare them. Example:MyAppSchema = GraphQLSchema( ... directives=specified_directives + [my_custom_directive])
-
__init__
(query: Optional[graphql.type.definition.GraphQLObjectType] = None, mutation: Optional[graphql.type.definition.GraphQLObjectType] = None, subscription: Optional[graphql.type.definition.GraphQLObjectType] = None, types: Optional[Collection[graphql.type.definition.GraphQLNamedType]] = None, directives: Optional[Collection[graphql.type.directives.GraphQLDirective]] = None, description: Optional[str] = None, extensions: Optional[Dict[str, Any]] = None, ast_node: Optional[graphql.language.ast.SchemaDefinitionNode] = None, extension_ast_nodes: Optional[Collection[graphql.language.ast.SchemaExtensionNode]] = None, assume_valid: bool = False) → None¶ Initialize GraphQL schema.
If this schema was built from a source known to be valid, then it may be marked with
assume_valid
to avoid an additional type system validation.
-
_implementations_map
: Dict[str, InterfaceImplementations]¶
-
_sub_type_map
: Dict[str, Set[str]]¶
-
_validation_errors
: Optional[List[GraphQLError]]¶
-
ast_node
: Optional[ast.SchemaDefinitionNode]¶
-
description
: Optional[str]¶
-
directives
: FrozenList[GraphQLDirective]¶
-
extension_ast_nodes
: Optional[FrozenList[ast.SchemaExtensionNode]]¶
-
extensions
: Optional[Dict[str, Any]]¶
-
get_directive
(name: str) → Optional[graphql.type.directives.GraphQLDirective]¶
-
get_implementations
(interface_type: graphql.type.definition.GraphQLInterfaceType) → graphql.type.schema.InterfaceImplementations¶
-
get_possible_types
(abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]) → List[graphql.type.definition.GraphQLObjectType]¶ Get list of all possible concrete types for given abstract type.
-
get_type
(name: str) → Optional[graphql.type.definition.GraphQLNamedType]¶
-
is_possible_type
(abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], possible_type: graphql.type.definition.GraphQLObjectType) → bool¶ Check whether a concrete type is possible for an abstract type.
Deprecated: Use is_sub_type() instead.
-
is_sub_type
(abstract_type: Union[graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType], maybe_sub_type: Union[graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType]) → bool¶ Check whether a type is a subtype of a given abstract type.
-
mutation_type
: Optional[GraphQLObjectType]¶
-
query_type
: Optional[GraphQLObjectType]¶
-
subscription_type
: Optional[GraphQLObjectType]¶
-
to_kwargs
() → Dict[str, Any]¶
-
type_map
: TypeMap¶
-
property
validation_errors
¶
-
Validate¶
Functions:¶
-
graphql.type.
validate_schema
(schema: graphql.type.schema.GraphQLSchema) → List[graphql.error.graphql_error.GraphQLError]¶ Validate a GraphQL schema.
Implements the “Type Validation” sub-sections of the specification’s “Type System” section.
Validation runs synchronously, returning a list of encountered errors, or an empty list if no errors were encountered and the Schema is valid.