Transform#
- subgrounds.transform.apply_transforms(request_transforms, document_transforms, req)#
- Apply all RequestTransforms and DocumentTransforms to a DataRequest and a
corresponding DataResponse.
This function abstractly applies a series of transforms onto a request and response. The execution of the request is handled outside this function (ala. sans-io), which
allows this function to only work with the abstracted components.
- Note: For simplification, all DocumentTransforms stored at the subgraph are
converted to specific RequestTransforms when applied.
- class subgrounds.transform.DocumentTransform#
Abstract class representing a transformation layer to be applied to
Document
objects.- transform_document(doc)#
Method that will be applied to all
Document
objects that pass through the transformation layer.
- transform_response(req, resp)#
Method to be applied to all response data
data
of requests that pass through the transformation layer.doc
is the initialDocument
object that yielded the resulting JSON datadata
.- Parameters:
doc -- Initial document
data -- Response resulting from the execution of the transformed document.
- Returns:
The transformed response data
- Return type:
- class subgrounds.transform.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 fieldfmeta
by the argument fields selectionsargs
if the synthetic fieldfmeta
is present in the document.transform_response()
appliedf
to the fields corresponding to the argument selectionsargs
and places the result in the response.- 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.
- transform_document(doc)#
Method that will be applied to all
Document
objects that pass through the transformation layer.
- transform_response(doc, resp)#
Method to be applied to all response data
data
of requests that pass through the transformation layer.doc
is the initialDocument
object that yielded the resulting JSON datadata
.- Parameters:
doc (Document) -- Initial document
data -- Response resulting from the execution of the transformed document.
- Returns:
The transformed response data
- Return type:
- class subgrounds.transform.RequestTransform#
Abstract class representing a transformation layer to be applied to entire
DataRequest
objects.- 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
- Return type:
- transform_response(req, resp)#
Method to be applied to all response data
data
of requests that pass through the transformation layer.req
is the initialDataRequest
object that yielded the resulting JSON datadata
.- Parameters:
req (DataRequest) -- Initial data request object
data -- Response resulting from the execution of the transformed data request.
- Returns:
The transformed response data
- Return type:
- class subgrounds.transform.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.
- transform_response(doc, resp)#
Method to be applied to all response data
data
of requests that pass through the transformation layer.doc
is the initialDocument
object that yielded the resulting JSON datadata
.- Parameters:
doc (Document) -- Initial document
data -- Response resulting from the execution of the transformed document.
- Returns:
The transformed response data
- Return type: