ayon_api.graphql module¶
- class BaseGraphQlQueryField(name: str, parent: Union[BaseGraphQlQueryField, GraphQlQuery], order: SortOrder)[source]¶
Bases:
ABCField in GraphQl query.
- Parameters:
name (
str) – Name of field.parent (
Union[BaseGraphQlQueryField, GraphQlQuery]) – Parent object of a field.
- add_field(name: str) GraphQlQueryField[source]¶
- add_field_with_edges(name: str) GraphQlQueryEdgeField[source]¶
- add_obj_field(field: BaseGraphQlQueryField) None[source]¶
- add_variable(key: str, value_type: str, value: Optional[Any] = None) QueryVariable[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:
- Raises:
KeyError – If variable was already added before.
- property child_has_edges: bool¶
- abstract property child_indent: int¶
- get_field_by_keys(keys: Iterable[str]) Optional[BaseGraphQlQueryField][source]¶
- get_filters() dict[str, Any][source]¶
Receive filters for item.
By default just use copy of set filters.
- Returns:
Fields filters.
- Return type:
dict[str, Any]
- get_variable(key: str) QueryVariable[source]¶
Variable object.
- Parameters:
key (
str) – Variable name added to headers.- Returns:
Variable object used in query string.
- Return type:
- abstract property has_edges: bool¶
- property indent: int¶
- property name: str¶
- property need_query: bool¶
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: int¶
- abstract parse_result(data: dict[str, Any], output: dict[str, Any], progress_data: dict[str, Any]) None[source]¶
- property path: str¶
Field path for debugging purposes.
- Returns:
Field path in query.
- Return type:
str
- property query_item: GraphQlQuery¶
- set_parent(parent: Union[BaseGraphQlQueryField, GraphQlQuery]) None[source]¶
- sum_edge_fields(max_limit: Optional[int] = None) int[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: str, order: Optional[int] = None)[source]¶
Bases:
objectGraphQl 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: str) GraphQlQueryField[source]¶
Add field to query.
- Parameters:
name (
str) – Field name e.g. ‘id’.- Returns:
Created field object.
- Return type:
- add_field_with_edges(name: str) GraphQlQueryEdgeField[source]¶
Add field with edges to query.
- Parameters:
name (
str) – Field name e.g. ‘tasks’.- Returns:
Created field object.
- Return type:
- add_obj_field(field: BaseGraphQlQueryField) None[source]¶
Add field object to children.
- Parameters:
field (
BaseGraphQlQueryField) – Add field to query children.
- add_variable(key: str, value_type: str, value: Optional[Any] = None) QueryVariable[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:
- Raises:
KeyError – If variable was already added before.
- calculate_query() str[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: int¶
Indentation for preparation of query string used by children.
- Returns:
Ident spaces for children.
- Return type:
int
- continuous_query(con: ServerAPI) Generator[dict[str, Any], None, None][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_field_by_keys(keys: Iterable[str]) Optional[BaseGraphQlQueryField][source]¶
- get_field_by_path(path: str) Optional[BaseGraphQlQueryField][source]¶
- get_variable(key: str) QueryVariable[source]¶
Variable object.
- Parameters:
key (
str) – Variable name added to headers.- Returns:
Variable object used in query string.
- Return type:
- get_variable_keys() set[str][source]¶
Get all variable keys.
- Returns:
Variable keys.
- Return type:
set[str]
- get_variable_value(key: str, default: Optional[Any] = None) Any[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() dict[str, Any][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: bool¶
- property indent: int¶
Indentation for preparation of query string.
- Returns:
Ident spaces.
- Return type:
int
- property need_query: bool¶
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: dict[str, Any], output: dict[str, Any], progress_data: dict[str, Any]) None[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.
- class GraphQlQueryEdgeField(*args, **kwargs)[source]¶
Bases:
BaseGraphQlQueryField- add_edge_field(name: str) GraphQlQueryField[source]¶
- add_obj_edge_field(field: BaseGraphQlQueryField) None[source]¶
- add_obj_field(field: BaseGraphQlQueryField) None[source]¶
- property child_indent: int¶
- get_filters() dict[str, Any][source]¶
Receive filters for item.
By default just use copy of set filters.
- Returns:
Fields filters.
- Return type:
dict[str, Any]
- has_edges = True¶
- class GraphQlQueryField(name: str, parent: Union[BaseGraphQlQueryField, GraphQlQuery], order: SortOrder)[source]¶
Bases:
BaseGraphQlQueryField- property child_indent: int¶
- has_edges = False¶
- class QueryVariable(variable_name: str)[source]¶
Bases:
objectObject 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: str¶
Name used in field filter.
- property variable_name: str¶
Name of variable in query definition.