ayon_api.graphql module

class BaseGraphQlQueryField(name, parent)[source]

Bases: ABC

Field in GraphQl query.

Parameters:
  • name (str) – Name of field.

  • parent (Union[BaseGraphQlQueryField, GraphQlQuery]) – Parent object of a field.

add_field(name)[source]
add_field_with_edges(name)[source]
add_obj_field(field)[source]
add_variable(key, value_type, value=None)[source]

Add variable to query.

Parameters:
  • key (str) – Variable name.

  • value_type (str) – Type of expected value in variables. This is graphql type e.g. “[String!]”, “Int”, “Boolean”, etc.

  • value (Any) – Default value for variable. Can be changed later.

Returns:

Created variable object.

Return type:

QueryVariable

Raises:

KeyError – If variable was already added before.

abstract calculate_query()[source]
property child_has_edges
abstract property child_indent
get_filters()[source]

Receive filters for item.

By default just use copy of set filters.

Returns:

Fields filters.

Return type:

Dict[str, Any]

get_variable(key)[source]

Variable object.

Parameters:

key (str) – Variable name added to headers.

Returns:

Variable object used in query string.

Return type:

QueryVariable

get_variable_value(*args, **kwargs)[source]
abstract property has_edges
has_filter(key)[source]
property indent
property need_query

Still need query from server.

Needed for edges which use pagination. Look into children values too.

Returns:

If still need query from server.

Return type:

bool

property offset
abstract parse_result(data, output, progress_data)[source]
property path

Field path for debugging purposes.

Returns:

Field path in query.

Return type:

str

property query_item
remove_filter(key)[source]
reset_cursor()[source]
set_filter(key, value)[source]
set_parent(parent)[source]
set_variable_value(*args, **kwargs)[source]
sum_edge_fields(max_limit=None)[source]

Check how many edge fields query has.

In case there are multiple edge fields or are nested the query can’t yield mid cursor results.

Parameters:

max_limit (int) – Skip rest of counting if counter is bigger then entered number.

Returns:

Counter edge fields

Return type:

int

class GraphQlQuery(name)[source]

Bases: object

GraphQl query which can have fields to query.

Single use object which can be used only for one query. Object and children objects keep track about paging and progress.

Parameters:

name (str) – Name of query.

add_field(name)[source]

Add field to query.

Parameters:

name (str) – Field name e.g. ‘id’.

Returns:

Created field object.

Return type:

GraphQlQueryField

add_field_with_edges(name)[source]

Add field with edges to query.

Parameters:

name (str) – Field name e.g. ‘tasks’.

Returns:

Created field object.

Return type:

GraphQlQueryEdgeField

add_obj_field(field)[source]

Add field object to children.

Parameters:

field (BaseGraphQlQueryField) – Add field to query children.

add_variable(key, value_type, value=None)[source]

Add variable to query.

Parameters:
  • key (str) – Variable name.

  • value_type (str) – Type of expected value in variables. This is graphql type e.g. “[String!]”, “Int”, “Boolean”, etc.

  • value (Any) – Default value for variable. Can be changed later.

Returns:

Created variable object.

Return type:

QueryVariable

Raises:

KeyError – If variable was already added before.

calculate_query()[source]

Calculate query string which is sent to server.

Returns:

GraphQl string with variables and headers.

Return type:

str

Raises:

ValueError – Query has no fiels.

property child_indent

Indentation for preparation of query string used by children.

Returns:

Ident spaces for children.

Return type:

int

continuous_query(con)[source]

Do a query from server.

Parameters:

con (ServerAPI) – Connection to server with ‘query’ method.

Returns:

Parsed output from GraphQl query.

Return type:

Dict[str, Any]

get_variable(key)[source]

Variable object.

Parameters:

key (str) – Variable name added to headers.

Returns:

Variable object used in query string.

Return type:

QueryVariable

get_variable_keys()[source]

Get all variable keys.

Returns:

Variable keys.

Return type:

set[str]

get_variable_value(key, default=None)[source]

Get Current value of variable.

Parameters:
  • key (str) – Variable name.

  • default (Any) – Default value if variable is available.

Returns:

Variable value.

Return type:

Any

get_variables_values()[source]

Calculate variable values used that should be used in query.

Variables with value set to ‘None’ are skipped.

Returns:

Variable values by their name.

Return type:

Dict[str, Any]

property has_multiple_edge_fields
property indent

Indentation for preparation of query string.

Returns:

Ident spaces.

Return type:

int

property need_query

Still need query from server.

Needed for edges which use pagination.

Returns:

If still need query from server.

Return type:

bool

offset = 2
parse_result(data, output, progress_data)[source]

Parse data from response for output.

Output is stored to passed ‘output’ variable. That’s because of paging during which objects must have access to both new and previous values.

Parameters:
  • data (Dict[str, Any]) – Data received using calculated query.

  • output (Dict[str, Any]) – Where parsed data are stored.

  • progress_data (Dict[str, Any]) – Data used for paging.

query(con)[source]

Do a query from server.

Parameters:

con (ServerAPI) – Connection to server with ‘query’ method.

Returns:

Parsed output from GraphQl query.

Return type:

Dict[str, Any]

set_variable_value(key, value)[source]

Set value for variable.

Parameters:
  • key (str) – Variable name under which the value is stored.

  • value (Any) – Variable value used in query. Variable is not used if value is ‘None’.

class GraphQlQueryEdgeField(*args, **kwargs)[source]

Bases: BaseGraphQlQueryField

add_edge_field(name)[source]
add_obj_edge_field(field)[source]
add_obj_field(field)[source]
calculate_query()[source]
property child_indent
get_filters()[source]

Receive filters for item.

By default just use copy of set filters.

Returns:

Fields filters.

Return type:

Dict[str, Any]

has_edges = True
parse_result(data, output, progress_data)[source]
reset_cursor()[source]
class GraphQlQueryField(name, parent)[source]

Bases: BaseGraphQlQueryField

calculate_query()[source]
property child_indent
has_edges = False
parse_result(data, output, progress_data)[source]
class QueryVariable(variable_name)[source]

Bases: object

Object representing single varible used in GraphQlQuery.

Variable definition is in GraphQl query header but it’s value is used in fields.

Parameters:

variable_name (str) – Name of variable in query.

property name

Name used in field filter.

property variable_name

Name of variable in query definition.

fields_to_dict(fields)[source]