subgrounds.schema module
Schema data structure module
This module contains various data structures in the form of dataclasses that are used to represent GraphQL schemas in Subgrounds using an AST-like approach.
- class subgrounds.schema.TypeRef
Bases:
objectClass used as namespace for all types and functions related to GraphQL schema type references.
- class Named(name_)
Bases:
subgrounds.schema.TypeRef.TClass used to represent a simple type reference.
- class NonNull(inner)
Bases:
subgrounds.schema.TypeRef.TClass used to represent a non-nullable type reference.
- inner: subgrounds.schema.TypeRef.T
- class List(inner)
Bases:
subgrounds.schema.TypeRef.TClass used to represent a list type reference.
- inner: subgrounds.schema.TypeRef.T
- static non_null(name)
- static non_null_list(name)
- static root_type_name(type_)
- static is_non_null(type_)
- static is_list(type_)
- static graphql(type_)
- class subgrounds.schema.TypeMeta
Bases:
objectClass used as namespace for all types and functions related to GraphQL schema types.
- class ArgumentMeta(name, description, type_, default_value)
Bases:
subgrounds.schema.TypeMeta.TClass representing a field argument definition.
- type_: subgrounds.schema.TypeRef.T
- class FieldMeta(name, description, arguments, type_)
Bases:
subgrounds.schema.TypeMeta.TClass representing an object field definition.
- arguments: list[subgrounds.schema.TypeMeta.ArgumentMeta]
- type_: subgrounds.schema.TypeRef.T
- has_arg(argname)
- type_of_arg(argname)
- class ScalarMeta(name, description)
Bases:
subgrounds.schema.TypeMeta.TClass representing an scalar definition.
- class ObjectMeta(name, description, fields, interfaces=<factory>)
Bases:
subgrounds.schema.TypeMeta.TClass representing an object definition.
- field(fname)
Returns the field definition of object
selfwith namefname, if any.- Parameters
self (TypeMeta.ObjectMeta) -- The object type
fname (str) -- The name of the desired field definition
- Raises
KeyError -- If no field named
fnameis defined for objectself.- Returns
The field definition
- Return type
- type_of_field(fname)
Returns the type reference of the field of object
selfwith namefname, if any.- Parameters
self (TypeMeta.ObjectMeta) -- The object type
fname (str) -- The name of the desired field type
- Raises
KeyError -- If no field named
fnameis defined for objectself.- Returns
The field type reference
- Return type
- class EnumValueMeta(name, description)
Bases:
subgrounds.schema.TypeMeta.TClass representing an enum value definition.
- class EnumMeta(name, description, values)
Bases:
subgrounds.schema.TypeMeta.TClass representing an enum definition.
- class InterfaceMeta(name, description, fields)
Bases:
subgrounds.schema.TypeMeta.TClass representing an interface definition.
- field(fname)
Returns the field definition of interface self with name fname, if any.
- Parameters
self (TypeMeta.InterfaceMeta) -- The interface type
fname (str) -- The name of the desired field definition
- Raises
KeyError -- If no field named
fnameis defined for interfaceself.- Returns
The field definition
- Return type
- type_of_field(fname)
Returns the type reference of the field of interface self with name fname, if any.
- Parameters
self (TypeMeta.InterfaceMeta) -- The interface type
fname (str) -- The name of the desired field type
- Raises
KeyError -- If no field named fname is defined for interface self.
- Returns
The field type reference
- Return type
- class UnionMeta(name, description, types)
Bases:
subgrounds.schema.TypeMeta.TClass representing an union definition.
- class InputObjectMeta(name, description, input_fields)
Bases:
subgrounds.schema.TypeMeta.TClass representing an input object definition.
- input_fields: list[subgrounds.schema.TypeMeta.ArgumentMeta]
- type_of_input_field(fname)
Returns the type reference of the input field named fname in the input object self, if any.
- Parameters
self (TypeMeta.InputObjectMeta) -- The input object
fname (str) -- The name of the input field
- Raises
KeyError -- If fname is not an input field of input object self
- Returns
The type reference for input field fname
- Return type
- class subgrounds.schema.SchemaMeta(query_type, type_map, mutation_type=None, subscription_type=None)
Bases:
objectClass representing a GrpahQL schema.
Contains all type definitions.
- type_map: dict[str, subgrounds.schema.TypeMeta.T]
- type_of_typeref(typeref)
Returns the type information of the type reference typeref
- Parameters
self (SchemaMeta) -- The schema.
typeref (TypeRef.T) -- The type reference pointing to the type of interest.
- Raises
KeyError -- If the type reference refers to a non-existant type
- Returns
_description_
- Return type
- type_of(tmeta)
Returns the argument or field definition's underlying type.
- subgrounds.schema.mk_schema(json)
Builds the schema data structure from a dictionary containing a JSON GraphQL schema definition (the result of the introspection query on a GraphQL API endpoint).
- Parameters
- Returns
A schema data structure
- Return type