ds_provider_xledger_py_lib.utils.graphql

File: graphql.py Region: ds_provider_xledger_py_lib/utils

Description

Helpers for normalizing GraphQL responses and errors.

Attributes

logger

Functions

raise_for_graphql_errors(→ dict[str, Any])

Raise typed DS exceptions for GraphQL payload errors.

map_graphql_errors_to_exception(→ Exception)

Map GraphQL payload errors to typed Xledger dataset exceptions.

_build_exception(→ Exception)

Instantiate an exception with explicit message and optional status code.

_parse_error(→ tuple[str, str, str])

Extract message/code metadata from a GraphQL error object.

_extract_status_code(→ int | None)

Best-effort extraction of HTTP-like status code from GraphQL error.

Module Contents

ds_provider_xledger_py_lib.utils.graphql.logger
ds_provider_xledger_py_lib.utils.graphql.raise_for_graphql_errors(*, body: Any) dict[str, Any][source]

Raise typed DS exceptions for GraphQL payload errors.

GraphQL servers may return HTTP 200 while reporting failures under an errors field in the response payload.

Parameters:

body – The GraphQL response body to inspect.

Returns:

The original GraphQL response body when no error is present.

ds_provider_xledger_py_lib.utils.graphql.map_graphql_errors_to_exception(*, errors: list[Any]) Exception[source]

Map GraphQL payload errors to typed Xledger dataset exceptions.

Parameters:

errors – The GraphQL errors to map to exceptions.

Returns:

The mapped exception.

ds_provider_xledger_py_lib.utils.graphql._build_exception(exc_cls: type[Exception], *, message: str | None = None, status_code: int | None = None) Exception[source]

Instantiate an exception with explicit message and optional status code.

Parameters:
  • exc_cls – The exception class to instantiate.

  • message – Optional message to include in the exception.

  • status_code – Optional HTTP-like status code. When omitted, the exception class handles its own default status behavior.

ds_provider_xledger_py_lib.utils.graphql._parse_error(error: Any) tuple[str, str, str][source]

Extract message/code metadata from a GraphQL error object.

Parameters:

error – The GraphQL error to parse.

Returns:

A tuple containing the message, code, and extension code.

ds_provider_xledger_py_lib.utils.graphql._extract_status_code(error: Any) int | None[source]

Best-effort extraction of HTTP-like status code from GraphQL error.

Parameters:

error – The GraphQL error to extract the status code from.

Returns:

The HTTP-like status code from the GraphQL error.