ds_provider_xledger_py_lib.utils.query_builder¶
File: query_builder.py
Region: ds_provider_xledger_py_lib/utils
Description¶
GraphQL query/mutation template rendering helpers.
Attributes¶
Functions¶
|
Build GraphQL variables payload for an operation. |
|
Build a rendered GraphQL query for read operations. |
|
Build a rendered GraphQL mutation for write operations. |
|
Render supported placeholders in packaged GraphQL templates. |
|
Build GraphQL selection set string from flattened field metadata. |
|
Format nested selection tree into GraphQL selection syntax. |
|
Resolve fields to render for query/mutation selection. |
|
Apply provided keyword arguments to the first query argument block. |
|
Extract query arguments from a query string. |
|
Upsert argument value in a query argument block. |
|
Convert Python values into GraphQL literal fragments. |
|
Assign value to flat or |
|
Build |
|
Build a filtered GraphQL node from a dataframe row record. |
|
Build delete operation variables from |
Module Contents¶
- ds_provider_xledger_py_lib.utils.query_builder._FIELDS_PLACEHOLDER = '{{ FIELDS }}'¶
- ds_provider_xledger_py_lib.utils.query_builder._DBIDS_PLACEHOLDER = '{{ DBIDS }}'¶
- ds_provider_xledger_py_lib.utils.query_builder._WRITE_OPERATIONS¶
- ds_provider_xledger_py_lib.utils.query_builder._QUERY_ARG_MAPPINGS = (('first', 'first'), ('last', 'last'), ('before', 'before'), ('after', 'after'), ('filter',...¶
- ds_provider_xledger_py_lib.utils.query_builder.build_variables(*, obj: pandas.DataFrame, operation: ds_provider_xledger_py_lib.enums.OperationType, metadata: ds_provider_xledger_py_lib.utils.introspection.MetaData) dict[str, Any][source]¶
Build GraphQL variables payload for an operation.
- Parameters:
obj – Input dataframe.
operation – Dataset operation type.
metadata – Loaded operation metadata.
- Returns:
Variables dictionary matching the query template.
- ds_provider_xledger_py_lib.utils.query_builder.build_query(*, metadata: ds_provider_xledger_py_lib.utils.introspection.MetaData, **kwargs: Any) str[source]¶
Build a rendered GraphQL query for read operations.
- Parameters:
metadata – Operation metadata.
**kwargs – Query keyword arguments.
fieldscontrols selection set.
- Returns:
GraphQL query text.
- ds_provider_xledger_py_lib.utils.query_builder.build_mutation(*, metadata: ds_provider_xledger_py_lib.utils.introspection.MetaData, variables: dict[str, Any], return_fields: list[str] | None = None) str[source]¶
Build a rendered GraphQL mutation for write operations.
- Parameters:
metadata – Operation metadata.
variables – Resolved variables required by the mutation template.
return_fields – Optional explicit fields to return.
- Returns:
GraphQL mutation text.
- ds_provider_xledger_py_lib.utils.query_builder._render_template(*, template: str, field_names: list[str], variables: dict[str, Any]) str[source]¶
Render supported placeholders in packaged GraphQL templates.
- Parameters:
template – Raw GraphQL template from metadata.
field_names – Field names to include in
nodeselections.variables – Prepared variables payload used for placeholder expansion.
- Returns:
Query template with known placeholders expanded.
- ds_provider_xledger_py_lib.utils.query_builder._build_selection_set(fields: list[str]) str[source]¶
Build GraphQL selection set string from flattened field metadata.
- Parameters:
fields – Operation fields from metadata.
- Returns:
GraphQL selection set string.
- ds_provider_xledger_py_lib.utils.query_builder._format_tree(tree: dict[str, Any]) str[source]¶
Format nested selection tree into GraphQL selection syntax.
- Parameters:
tree – Nested dictionary representing selection structure.
- Returns:
Selection set fragment string.
- ds_provider_xledger_py_lib.utils.query_builder._resolve_fields(*, metadata: ds_provider_xledger_py_lib.utils.introspection.MetaData, requested_fields: list[str] | None) list[str][source]¶
Resolve fields to render for query/mutation selection.
- Parameters:
metadata – Operation metadata.
requested_fields – Requested fields to include in the selection set.
- Returns:
List of fields to include in the selection set.
- ds_provider_xledger_py_lib.utils.query_builder._apply_query_arguments(*, query: str, **kwargs: Any) str[source]¶
Apply provided keyword arguments to the first query argument block.
- Parameters:
query – The query string.
**kwargs – Query keyword arguments.
- Returns:
The updated query string.
- ds_provider_xledger_py_lib.utils.query_builder._extract_query_args(query: str) str[source]¶
Extract query arguments from a query string.
- Parameters:
query – The query string.
- Returns:
The query arguments string.
- ds_provider_xledger_py_lib.utils.query_builder._upsert_query_arg(*, query_args: str, arg_name: str, value_literal: str) str[source]¶
Upsert argument value in a query argument block.
- Parameters:
query_args – The query arguments string.
arg_name – GraphQL argument name.
value_literal – GraphQL literal value.
- Returns:
Updated query arguments string with arg replaced or appended.
- ds_provider_xledger_py_lib.utils.query_builder._to_graphql_literal(value: Any) str[source]¶
Convert Python values into GraphQL literal fragments.
- Parameters:
value – The value to convert.
- Returns:
The GraphQL literal string.
- ds_provider_xledger_py_lib.utils.query_builder._assign_nested_key(*, target: dict[str, Any], key: str, value: Any) None[source]¶
Assign value to flat or
a_bnested key path.- Parameters:
target – Target dictionary being built.
key – Field name. Supports flattened relation style (
a_b).value – Field value to assign.
- ds_provider_xledger_py_lib.utils.query_builder._build_placeholder_input(*, records: list[dict[str, Any]], allowed_fields: set[str]) list[dict[str, Any]][source]¶
Build
PlaceHolderInputpayload list for create/update operations.- Parameters:
records – List of records to build placeholder input from.
allowed_fields – Allowed fields to include in the placeholder input.
- Returns:
List of placeholder input.
- ds_provider_xledger_py_lib.utils.query_builder._build_node(*, record: dict[str, Any], allowed_fields: set[str]) dict[str, Any][source]¶
Build a filtered GraphQL node from a dataframe row record.
- Parameters:
record – Record to build node from.
allowed_fields – Allowed fields to include in the node.
- Returns:
Dictionary of node.
- ds_provider_xledger_py_lib.utils.query_builder._build_delete_variables(*, obj: pandas.DataFrame, records: list[dict[str, Any]]) dict[str, Any][source]¶
Build delete operation variables from
dbIdvalues when available.- Parameters:
obj – Input dataframe.
records – List of records to build delete variables from.
- Returns:
Dictionary of variables.