GraphQL
EnumValue
class
prefect.utilities.graphql.EnumValue
(value)
[source] When parsing GraphQL arguments, strings can be wrapped in this class to be rendered as enum values, without quotation marks.
Args:
value (str)
: the value that should be represented as an enum value
Functions
top-level functions: |
prefect.utilities.graphql.parse_graphql (document) [source] |
Parses a document into a GraphQL-compliant query string.
Documents can be a mix of strings , dicts , lists (or other sequences), and GQLObjects .
The parser attempts to maintain the form of the Python objects in the resulting GQL query.
For example:
query = parse_graphql({ 'query': { 'books(published: {gt: 1990})': { 'title' }, 'authors': [ 'name', 'books': { 'title' }] } } })
results in:
query { books(published: {gt: 1990}) { title } authors { name books { title } } }
For convenience, if a dictionary key is either True or Ellipsis(...), it is ignored and the key alone is used as a field name.
{'query':{ 'books': { 'id': True, 'name': ..., 'author': { 'id', 'name', } } }}
is equivalent to:
{'query':{ 'books': [ 'id', 'name', {'author': { 'id', 'name', }} ] }}
Args: document (Any) : A collection of Python objects complying with the general shape of a GraphQL query. Generally, this will consist of (at least) a dictionary, but also sequences and GQLObjects . Returns: str : a GraphQL query compiled from the provided Python structures. Raises: TypeError : if the user provided a GQLObject class, rather than an instance.
|
prefect.utilities.graphql.parse_graphql_arguments (arguments) [source] |
Parses a dictionary of GraphQL arguments, returning a GraphQL-compliant string representation. If a string is passed, it is returned without modification.
This parser makes a few adjustments to the dictionary's usual string representation: - ' around keys are removed - spaces added around curly braces - leading and lagging braces are removed - True becomes true , False becomes false , and None becomes null
Args: arguments (Any) : an object (usually a dictionary) representing the GraphQL arguments Returns: str : a string representing the parsed GraphQL arguments
|
prefect.utilities.graphql.with_args (field, arguments) [source] |
Given Python objects representing a field name and arguments, formats them as a single GraphQL compatible string.
Example:
query = parse_graphql({ 'query': { with_args("task", {"where": {"id": 3}}): { "id" } } })
assert query == ''' query { task(where: {id: 3}) { id } } '''
Args: field (Any) : the GraphQL field that will be supplied with arguments arguments (Any) : the arguments to be parsed and supplied to the field Returns: str : the parsed field and arguments
|
prefect.utilities.graphql.compress (input) [source] |
Convenience function for compressing something before sending it to Cloud. Converts to string, encodes, compresses, encodes again using b64, and decodes.
Args: input (Any) : the dictionary to be compressed Returns: str : The string resulting from the compression
|
prefect.utilities.graphql.decompress (string) [source] |
Convenience function for decompressing a string that's been compressed. Base64 decodes the string, decodes it, decompresses it, and loads.
Args: string (str) : the string to decompress Returns: Any : The object resulting from the decompression
|
This documentation was auto-generated from commit bd9182e
on July 31, 2024 at 18:02 UTC