links.transpile
TranspileHandler Objects
class TranspileHandler(BaseModel)
A Transpilation Handler
A TranspileHandler is a function that takes any Any and returns a GraphQLType. It is used to implement custom type resolution.
The default TranspileHandler is the identity function, which returns the type passed to it.
ListTranspileHandler Objects
class ListTranspileHandler(BaseModel)
A List Transpile Handler
Similar to a TranspileHandler, but takes act on GraphqQLList Type of that type
TranspilationError Objects
class TranspilationError(Exception)
A transpilation Exception
TranspilationHandlerException Objects
class TranspilationHandlerException(TranspilationError)
A transpilation Exception happening within a TranspileHandler
TranspileRegistry Objects
class TranspileRegistry(BaseModel)
A Registry to hold TranspileHandlers
register_item
def register_item(graphql_type: str,
                  predicate: Callable[[Any], bool],
                  name=None)
A Decorator for registering a TranspileHandler
If acting on a List of this type, the handle_list parameter should be set to True.
Example:
registry = TranspileRegistry()
@registry.register_item("ID", lambda x: isinstance(x, BaseModel))
def transpile_id_to_id(x):
return str(x.id)
Arguments:
graphql_typestr - The graphql Type to act uponpredicateCallable[[Any], bool] - A predicate Functionname_type, optional_ - A name for this hanlder. Defaults to the function name.
register_list
def register_list(graphql_type: str,
                  predicate: Callable[[Any, str], bool],
                  name=None)
A Decorator for registering a TranspileHandler
If acting on a List of this type, the handle_list parameter should be set to True.
Example:
registry = TranspileRegistry()
@registry.register_list("InputVector", lambda x, listdepth: isinstance(x, np.ndarray))
def transpile_numpy_array_to_vectors(x, listdepth):
assert listdepth == 1, "Only one level of nesting is supported"
return [InputVector(x) for x in x]
Arguments:
graphql_typestr - The graphql Type to act uponpredicateCallable[[Any], bool] - A predicate Functionhandle_listbool, optional - Should we act on lists of this type. Defaults to False.name_type, optional_ - A name for this hanlder. Defaults to the function name.
recurse_transpile
def recurse_transpile(key,
                      var: VariableNode,
                      value: Any,
                      registry: TranspileRegistry,
                      in_list=0,
                      strict=False)
Recurse Transpile a variable according to a registry and its definition
Arguments:
keytype - The key of the variablevarVariableNode - The variable definition node correspoin to this variablevalueAny - The to transpile valuedregistryTranspileRegistry - The transpile registry to usein_listbool, optional - Recursive Parameter. That will be set to the list depth. Defaults to False.strictbool, optional - Should we error on predicate errors. Defaults to False.
Raises:
TranspilationError- description
Returns:
Any- The transpiled value or the original value if no handler matched
transpile
def transpile(op: OperationDefinitionNode,
              variables: Dict[str, Any],
              registry: TranspileRegistry,
              strict=False) -> Dict[str, Any]
Transpile
Transpiles a operations variabels to a dictionary of variables, with json serializable values according to a transpile registry.
Arguments:
opOperationDefinitionNode - The operation definition node,registryTranspileRegistry - The registrystrictbool, optional - Should we fail if a handler predicate fails. Defaults to False.
Returns:
Dict- The transpiled variables
TranspileLink Objects
class TranspileLink(ParsingLink)
Transpile Link
Transpile Link is a link that transpiles variables according to a transpile registry.
Attributes:
registryTranspileRegistry - The transpile registry to usestrictbool - Should we fail if a handler predicate fails. Defaults to False.