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.BaseModel#

Bases: BaseModel

class Config#

Bases: object

allow_population_by_field_name = True#
class subgrounds.schema.TypeRef#

Bases: object

class T#

Bases: BaseModel

Base class of all types of type references.

property name: str#
property is_list: bool#
property is_non_null: bool#
class Named(*, name, kind)#

Bases: T

name_: str#
kind: str#
property name: str#
class NonNull(*, ofType, kind='NON_NULL')#

Bases: T

inner: Union[List, NonNull, Named]#
kind: Literal['NON_NULL']#
property name: str#
property is_list: bool#
property is_non_null: bool#
class List(*, ofType, kind='LIST')#

Bases: T

inner: Union[List, NonNull, Named]#
kind: Literal['LIST']#
property name: str#
property is_list: bool#
property is_non_null: bool#
static non_null(name, kind='SCALAR')#
static non_null_list(name, kind='SCALAR')#
static root_type_name(type_)#
static is_non_null(type_)#
static is_list(type_)#
static graphql(type_)#
class subgrounds.schema.TypeMeta#

Bases: object

class T(*, name, description=None)#

Bases: BaseModel

Base class of all GraphQL schema types.

name: str#
description: str | None#
property is_object: bool#
class ArgumentMeta(*, name, description=None, type, defaultValue=None)#

Bases: T

Class representing a field argument definition.

type_: Union[List, NonNull, Named]#
default_value: str | None#
class FieldMeta(*, name, description=None, args, type)#

Bases: T

Class representing an object field definition.

arguments: list[subgrounds.schema.TypeMeta.ArgumentMeta]#
type_: Union[List, NonNull, Named]#
has_arg(argname)#
type_of_arg(argname)#
class ScalarMeta(*, name, description=None, kind='SCALAR')#

Bases: T

kind: Literal['SCALAR']#

Class representing an scalar definition.

class ObjectMeta(*, name, description=None, kind='OBJECT', fields, interfaces=None)#

Bases: T

Class representing an object definition.

kind: Literal['OBJECT']#
fields: list[subgrounds.schema.TypeMeta.FieldMeta]#
interfaces_: list[dict]#
property interfaces: list[str]#
property is_object: bool#
field(fname)#

Returns the field definition of object self with name fname, if any.

Parameters:
Raises:

KeyError -- If no field named fname is defined for object self.

Returns:

The field definition

Return type:

TypeMeta.FieldMeta

type_of_field(fname)#

Returns the type reference of the field of object self with name fname, if any.

Parameters:
Raises:

KeyError -- If no field named fname is defined for object self.

Returns:

The field type reference

Return type:

TypeRef.T

class EnumValueMeta(*, name, description=None)#

Bases: T

Class representing an enum value definition.

class EnumMeta(*, name, description=None, kind='ENUM', enumValues)#

Bases: T

Class representing an enum definition.

kind: Literal['ENUM']#
values: list[subgrounds.schema.TypeMeta.EnumValueMeta]#
class InterfaceMeta(*, name, description=None, kind='INTERFACE', fields)#

Bases: T

Class representing an interface definition.

kind: Literal['INTERFACE']#
fields: list[subgrounds.schema.TypeMeta.FieldMeta]#
property is_object: bool#
field(fname)#

Returns the field definition of interface self with name fname, if any.

Parameters:
Raises:

KeyError -- If no field named fname is defined for interface self.

Returns:

The field definition

Return type:

TypeMeta.FieldMeta

class UnionMeta(*, name, description=None, kind='UNION', possibleTypes)#

Bases: T

Class representing an union definition.

kind: Literal['UNION']#
types: list[str]#
class InputObjectMeta(*, name, description=None, kind='INPUT_OBJECT', inputFields)#

Bases: T

Class representing an input object definition.

kind: Literal['INPUT_OBJECT']#
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:
Raises:

KeyError -- If fname is not an input field of input object self

Returns:

The type reference for input field fname

Return type:

TypeRef.T

class subgrounds.schema.SchemaMeta(*, queryType, types, type_map=None, mutationType=None, subscriptionType=None)#

Bases: BaseModel

Class representing a GraphQL schema.

Contains all type definitions.

query_type_: dict[str, str]#
types: list[subgrounds.schema.TypeMeta.ScalarMeta | subgrounds.schema.TypeMeta.ObjectMeta | subgrounds.schema.TypeMeta.EnumMeta | subgrounds.schema.TypeMeta.InterfaceMeta | subgrounds.schema.TypeMeta.UnionMeta | subgrounds.schema.TypeMeta.InputObjectMeta]#
type_map: dict[str, subgrounds.schema.TypeMeta.ScalarMeta | subgrounds.schema.TypeMeta.ObjectMeta | subgrounds.schema.TypeMeta.EnumMeta | subgrounds.schema.TypeMeta.InterfaceMeta | subgrounds.schema.TypeMeta.UnionMeta | subgrounds.schema.TypeMeta.InputObjectMeta]#
mutation_type_: dict[str, str] | None#
subscription_type_: dict[str, str] | None#
property query_type: str#
property mutation_type: str | None#
property subscription_type: str | None#
classmethod type_map_generator(values)#
type_of_typeref(typeref)#

Returns the type information of the type reference typeref

Args: 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: TypeMeta.T: _description_

type_of(tmeta)#

Returns the argument or field definition's underlying type

type_of_input_object_meta(tmeta, args)#

Recursively finds the nested type