ds_protocol_graphql_py_lib.dataset.graphql

File: graphql.py Region: ds_protocol_graphql_py_lib/dataset

GraphQL dataset implementation for CRUD operations via GraphQL API.

Example

>>> linked_service = HttpLinkedService(
...     settings=HttpLinkedServiceSettings(
...         host="https://api.example.graphql/graphql",
...         auth_type=AuthType.NO_AUTH,
...     ),
...     id="service-id",
...     name="graphql_service",
...     version="1.0.0",
... )
>>> dataset = GraphqlDataset(
...     linked_service=linked_service,
...     settings=GraphqlDatasetSettings(
...         url="https://api.example.graphql/graphql",
...         read=GraphqlReadSettings(
...             query="{ users { id name email } }"
...         ),
...     ),
...     id="dataset-id",
...     name="graphql_dataset",
...     version="1.0.0",
... )
>>> dataset.read()

Attributes

logger

GraphqlDatasetSettingsType

Classes

GraphqlReadSettings

Settings specific to reading data from GraphQL API.

GraphqlDeleteSettings

Settings specific to deleting data from GraphQL API.

GraphqlCreateSettings

Settings specific to creating data in GraphQL API.

GraphqlDatasetSettings

The object containing the settings of the dataset.

GraphqlDataset

Represent Graphql dataset.

Functions

_default_deserializer(...)

Module Contents

ds_protocol_graphql_py_lib.dataset.graphql.logger
class ds_protocol_graphql_py_lib.dataset.graphql.GraphqlReadSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Settings specific to reading data from GraphQL API.

query: str

The GraphQL query string to execute for reading data. This should be a valid GraphQL query that the endpoint can execute to return the desired data. For example: “{ users { id name email } }”

variables: dict[str, Any] | None = None

Optional variables to include with the GraphQL query.

operation_name: str | None = None

Optional operation name for the GraphQL query, used when the query contains multiple operations.

records_path: str | None = None

Optional path to the list of records in the response, e.g. “data.useCompany.associate.items”.

Each item in that list becomes one row of output. For Relay edges, a row is the node plus any extra fields on the edge (cursor is left out).

When unset: pagination.items_path if pagination is set, otherwise "data".

pagination: ds_protocol_graphql_py_lib.dataset.pagination.PaginationSettings | None = None

Optional pagination settings. When unset, read() issues a single request.

incremental: ds_protocol_graphql_py_lib.dataset.incremental.IncrementalSettings | None = None

Optional incremental watermark rules, consulted by Paginate.

Requires pagination: only paginated reads apply the watermark and keep the checkpoint (supports_checkpoint), so setting it alone is an error.

__post_init__() → None[source]
class ds_protocol_graphql_py_lib.dataset.graphql.GraphqlDeleteSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Settings specific to deleting data from GraphQL API.

mutation: str

The GraphQL mutation string to execute for deleting data.

identity_columns: list[str]

The list of column names in the input DataFrame that uniquely identify the rows to delete.

variables: dict[str, Any] | None = None

Optional variables to include with the GraphQL mutation.

operation_name: str | None = None

Optional operation name for the GraphQL mutation, used when the mutation contains multiple operations.

class ds_protocol_graphql_py_lib.dataset.graphql.GraphqlCreateSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Settings specific to creating data in GraphQL API.

mutation: str

The GraphQL mutation string to execute for creating data. This should be a valid GraphQL mutation that the endpoint can execute to create new records based on the input data. For example: “mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { id name email } }”

input_field: str

The name of the variable in the GraphQL mutation that will receive the input data.

operation_name: str | None = None

Optional operation name for the GraphQL mutation, used when the mutation contains multiple operations.

class ds_protocol_graphql_py_lib.dataset.graphql.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.dataset.graphql.GraphqlDatasetSettingsType
ds_protocol_graphql_py_lib.dataset.graphql._default_deserializer() → ds_protocol_graphql_py_lib.serde.deserializer.GraphqlDeserializer[source]
class ds_protocol_graphql_py_lib.dataset.graphql.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.