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