ds_protocol_graphql_py_lib

File: __init__.py Region: ds-protocol-graphql-py-lib

Description

A Python package from the ds-protocol-graphql-py-lib library.

Example

from ds_protocol_graphql_py_lib import __version__

print(f"Package version: {__version__}")

Submodules

Attributes

__version__

Classes

GraphqlDeserializer

Deserializer for GraphQL API responses.

GraphqlDataset

Represent Graphql dataset.

GraphqlDatasetSettings

The object containing the settings of the dataset.

Package Contents

class ds_protocol_graphql_py_lib.GraphqlDeserializer[source]

Bases: ds_resource_plugin_py_lib.common.serde.deserialize.PandasDeserializer

Deserializer for GraphQL API responses.

Starts at records_path (default "data") and turns the value there into rows: - Lists: one row per element - Relay edges (a list under edges, reached by the default path or a

records_path ending in .edges): see _edge_row()

  • Direct arrays: {“data”: {“users”: […]}}

  • Relay connections: {“data”: {“users”: {“edges”: [{“node”: {…}}]}}}

  • Single objects: {“data”: {“user”: {…}}}

  • Introspection queries: {“data”: {“__type”: {“fields”: […]}}}

deserialize_graphql(data: Any, records_path: str = DEFAULT_RECORDS_PATH) → pandas.DataFrame[source]

Deserialize GraphQL response to pandas DataFrame.

Parameters:
  • data – GraphQL response dict.

  • records_path – Dotted path on the full response where deserialization starts (default "data"), e.g. "data.useCompany.associate.items". The value there is parsed with the same rules as the default: lists become rows (Relay edges unwrapped to node), connections are unwrapped, single objects become one row. Missing or null yields an empty DataFrame. With the default path, a payload without a top-level "data" key is parsed as a whole (already unwrapped).

Returns:

DataFrame containing the extracted data

static _edge_row(edge: Any) → Any[source]

One Relay edge → one row, or None to skip it. Same rule on every path.

  • node is a dict: the row is the node’s fields plus the edge’s own fields (e.g. role on a membership edge). cursor and __typename describe the edge and are dropped; on a name clash the node’s value wins.

  • node is null: no record (e.g. deleted or hidden), skipped even when the edge has other fields.

  • null element: skipped.

  • Anything else (no node selected, or a non-dict node): kept as is.

_frame_from_edges(edges: list[Any]) → pandas.DataFrame[source]

Rows from a Relay edges list (see _edge_row()).

_frame_from_list(records: list[Any], *, key: str | None = None) → pandas.DataFrame[source]

One row per element. A list under edges is a Relay edge list; any other list is taken as rows unchanged (a node field there is data).

_parse_graphql_data(data: Any) → pandas.DataFrame[source]

Parse GraphQL data structure into DataFrame.

Handles nested structures and various GraphQL response patterns.

Parameters:

data – The data portion of the GraphQL response

Returns:

DataFrame with the extracted data

_handle_nested_dict(nested_value: dict[str, Any]) → pandas.DataFrame[source]

Handle nested dict - determine if it’s a pure array container or single object.

Parameters:

nested_value – The nested dictionary to analyze

Returns:

DataFrame with appropriate data extraction

_extract_relay_nodes(data: dict[str, Any]) → pandas.DataFrame[source]

Extract nodes from Relay-style pagination structure.

Parameters:

data – Dict containing “edges” key with Relay pagination structure

Returns:

DataFrame with one row per edge (see _edge_row()).

class ds_protocol_graphql_py_lib.GraphqlDataset[source]

Bases: ds_resource_plugin_py_lib.common.resource.dataset.TabularDataset[ds_protocol_http_py_lib.dataset.http.HttpLinkedServiceType, GraphqlDatasetSettingsType, ds_resource_plugin_py_lib.common.serde.serialize.PandasSerializer, ds_protocol_graphql_py_lib.serde.deserializer.GraphqlDeserializer], Generic[ds_protocol_http_py_lib.dataset.http.HttpLinkedServiceType, GraphqlDatasetSettingsType]

Represent Graphql dataset.

settings: GraphqlDatasetSettingsType
linked_service: ds_protocol_http_py_lib.dataset.http.HttpLinkedServiceType
deserializer: ds_protocol_graphql_py_lib.serde.deserializer.GraphqlDeserializer
__post_init__() → None[source]

Always use a GraphqlDeserializer: anything else (e.g. null from a stored config) is replaced.

property type: ds_protocol_graphql_py_lib.enums.ResourceType

Get the type of the dataset.

property supports_checkpoint: bool

Indicate whether this provider supports incremental loads via checkpointing.

True when pagination is configured: mid-run resume state is kept in checkpoint["pagination"] until a read completes.

Returns:

True if settings.read.pagination is set, else False.

read() → None[source]

Read Graphql dataset.

When settings.read.pagination is set, all pages are fetched via Paginate inside this single call (see “Pagination and incremental reads” in README.md). Otherwise sends a GraphQL query to the endpoint with the query, variables, and operation name specified in settings.read. Populates self.output with the result as a DataFrame.

Handles various GraphQL response patterns via GraphqlDeserializer: - Direct arrays: {“data”: {“users”: […]}} - Relay connections: {“data”: {“users”: {“edges”: [{“node”: {…}}]}}} - Single objects: {“data”: {“user”: {…}}}

Returns:

None. The result is stored in self.output as a DataFrame.

Raises:
  • ConnectionError – If the connection is not initialized, or the request cannot reach the server (raised by the linked service’s connection).

  • AuthenticationError – On HTTP 401 (raised by the linked service’s connection).

  • AuthorizationError – On HTTP 403 (raised by the linked service’s connection).

  • ReadError – If read settings are not provided, the GraphQL query fails, or on any other HTTP error status (with that status_code).

static _check_for_graphql_read_error(response_data: dict[str, Any]) → None[source]
create() → None[source]

Create new rows in the GraphQL endpoint using mutations.

Sends all rows in a single atomic GraphQL mutation request. Populates self.output with the created rows.

Returns:

None. The result is stored in self.output as a DataFrame.

Raises:
  • ConnectionError – If the linked service connection is not initialized.

  • CreateError – If create settings are not provided or if the GraphQL mutation fails.

update() → None[source]

Update entity using Graphql.

upsert() → None[source]

Upsert entity using Graphql.

delete() → None[source]

Delete specific rows from the GraphQL endpoint using mutations.

Sends all rows in a single atomic GraphQL mutation request. Populates self.output with the deleted rows.

Returns:

None. The result is stored in self.output as a DataFrame.

Raises:
  • ConnectionError – If the linked service connection is not initialized.

  • DeleteError – If delete settings are not provided, if identity columns are missing, or if the GraphQL mutation fails.

purge() → NoReturn[source]

Purge entity using Graphql.

rename() → NoReturn[source]

Rename entity using Graphql.

list() → None[source]

Discover available resources in the GraphQL schema via introspection.

Executes a GraphQL introspection query to fetch all available queries and their arguments from the schema. Populates self.output with a DataFrame containing resource metadata (name, type, description, etc.).

Returns:

None. The result is stored in self.output as a DataFrame.

Raises:
  • ConnectionError – If the linked service connection is not initialized.

  • ListError – If the GraphQL introspection query fails.

close() → None[source]

Just to satisfy the contract - GraphQL dataset does not maintain persistent connections that require cleanup.

Returns:

None

_validate_create_settings() → None[source]

Validate create settings are properly configured.

Returns:

if settings are valid.

Return type:

None

Raises:

CreateError – If any required create settings are missing or invalid.

class ds_protocol_graphql_py_lib.GraphqlDatasetSettings[source]

Bases: ds_resource_plugin_py_lib.common.resource.dataset.DatasetSettings

The object containing the settings of the dataset.

url: str

The URL of the GraphQL endpoint to connect to. This is the base URL where the GraphQL API is hosted.

primary_keys: list[str] | None = None

Optional list of column names that serve as primary keys for the dataset. This can be used for operations that require unique identification of rows.

headers: dict[str, str] | None = None

Optional HTTP headers to include in requests to the GraphQL endpoint, such as authentication tokens or content type.

read: GraphqlReadSettings | None = None

Settings for read operations.

delete: GraphqlDeleteSettings | None = None

Settings for delete operations.

create: GraphqlCreateSettings | None = None

Settings for create operations.

ds_protocol_graphql_py_lib.__version__