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: object

Class used as namespace for all types and functions related to GraphQL schema type references.

class T

Bases: abc.ABC

Base class of all types of type references.

abstract property name: str
abstract property is_list: bool
abstract property is_non_null: bool
class Named(name_)

Bases: subgrounds.schema.TypeRef.T

Class used to represent a simple type reference.

name_

Name of the type being referenced.

Type

str

name_: str
property name: str
property is_list: bool
property is_non_null: bool
class NonNull(inner)

Bases: subgrounds.schema.TypeRef.T

Class used to represent a non-nullable type reference.

inner

Non-nullable type being referenced.

Type

TypeRef.T

inner: subgrounds.schema.TypeRef.T
property name: str
property is_list: bool
property is_non_null: bool
class List(inner)

Bases: subgrounds.schema.TypeRef.T

Class used to represent a list type reference.

inner

List type being referenced.

Type

TypeRef.T

inner: subgrounds.schema.TypeRef.T
property name: str
property is_list: bool
property is_non_null: bool
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: object

Class used as namespace for all types and functions related to GraphQL schema types.

class T(name, description)

Bases: abc.ABC

Base class of all GraphQL schema types.

name: str
description: str
property is_object: bool
class ArgumentMeta(name, description, type_, default_value)

Bases: subgrounds.schema.TypeMeta.T

Class representing a field argument definition.

type_: subgrounds.schema.TypeRef.T
default_value: Optional[str]
class FieldMeta(name, description, arguments, type_)

Bases: subgrounds.schema.TypeMeta.T

Class 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.T

Class representing an scalar definition.

class ObjectMeta(name, description, fields, interfaces=<factory>)

Bases: subgrounds.schema.TypeMeta.T

Class representing an object definition.

fields: list[subgrounds.schema.TypeMeta.FieldMeta]
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)

Bases: subgrounds.schema.TypeMeta.T

Class representing an enum value definition.

class EnumMeta(name, description, values)

Bases: subgrounds.schema.TypeMeta.T

Class representing an enum definition.

values: list[subgrounds.schema.TypeMeta.EnumValueMeta]
class InterfaceMeta(name, description, fields)

Bases: subgrounds.schema.TypeMeta.T

Class representing an interface definition.

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

type_of_field(fname)

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

Parameters
Raises

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

Returns

The field type reference

Return type

TypeRef.T

class UnionMeta(name, description, types)

Bases: subgrounds.schema.TypeMeta.T

Class representing an union definition.

types: list[str]
class InputObjectMeta(name, description, input_fields)

Bases: subgrounds.schema.TypeMeta.T

Class 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
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(query_type, type_map, mutation_type=None, subscription_type=None)

Bases: object

Class representing a GrpahQL schema.

Contains all type definitions.

query_type: str
type_map: dict[str, subgrounds.schema.TypeMeta.T]
mutation_type: Optional[str] = None
subscription_type: Optional[str] = None
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

TypeMeta.T

type_of(tmeta)

Returns the argument or field definition's underlying type.

exception subgrounds.schema.ParsingError

Bases: Exception

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

json (dict[str, Any]) -- JSON GraphQL schema definition

Returns

A schema data structure

Return type

SchemaMeta