Transforms#

class subgrounds.transform.transforms.TypeTransform(type_, f)#

Transform to be applied to scalar fields on a per-type basis.

type_#

Type indicating which scalar values (i.e.: values of that type) should be transformed using the function f

Type:

subgrounds.schema.TypeRef.T

f#

Function to be applied to scalar values of type type_ in the response data.

Type:

Callable[[Any], Any]

transform_document(doc)#

Method that will be applied to all Document objects that pass through the transformation layer.

Parameters:

doc (Document) -- The initial document

Returns:

The transformed document

Return type:

Document

transform_response(doc, resp)#

Method to be applied to all response data data of requests that pass through the transformation layer.

doc is the initial Document object that yielded the resulting JSON data data.

Parameters:
  • doc (Document) -- Initial document

  • data -- Response resulting from the execution of the transformed document.

Returns:

The transformed response data

Return type:

DocumentResponse

class subgrounds.transform.transforms.LocalSyntheticField(subgraph, fmeta, type_, f, default, args)#

Transform used to implement synthetic fields on GraphQL objects that only depend on values accessible from that object.

transform_document() replaces the field fmeta by the argument fields selections args if the synthetic field fmeta is present in the document.

transform_response() applied f to the fields corresponding to the argument selections args and places the result in the response.

subgraph#

The subgraph to which the synthetic field's object belongs.

Type:

Subgraph

fmeta#

The synthetic field.

Type:

TypeMeta.FieldMeta

type_#

The object for which the synthetic field is defined.

Type:

TypeMeta.ObjectMeta | TypeMeta.InterfaceMeta

f#

The function to be applied to the argument fields.

Type:

Callable

default#

The default value of the synthetic field used in case of exceptions (e.g.: division by zero).

Type:

Any

args#

The selections of the fields used as arguments to compute the synthetic field.

Type:

list[Selection]

transform_document(doc)#

Method that will be applied to all Document objects that pass through the transformation layer.

Parameters:

doc (Document) -- The initial document

Returns:

The transformed document

Return type:

Document

transform_response(doc, resp)#

Method to be applied to all response data data of requests that pass through the transformation layer.

doc is the initial Document object that yielded the resulting JSON data data.

Parameters:
  • doc (Document) -- Initial document

  • data -- Response resulting from the execution of the transformed document.

Returns:

The transformed response data

Return type:

DocumentResponse

class subgrounds.transform.transforms.DocumentRequestTransform(transform, url)#

This class serves as a wrapper for DocumentTransform for ease of use.

Internally, we convert all :class:`DocumentTransform`s to

:class:`DocumentRequestTransform`s due to the relative ease it has on our implementation. We merely iterate through the documents within a request and response iterating them thru the relevant documents (based upon url).

transform_request(req)#

Method that will be applied to all DataRequest objects that pass through the transformation layer.

Parameters:

req (DataRequest) -- The initial request object

Returns:

The transformed request object

transform_response(req, data)#

Assumes 1 doc -> 1 resp, and ordering is correct via the zip