ds_protocol_graphql_py_lib.serde¶
File: __init__.py
Region: ds_protocol_graphql_py_lib/serde
Serialization and deserialization utilities for GraphQL protocol.
Example
>>> from ds_protocol_graphql_py_lib.serde import GraphqlDeserializer
>>> deserializer = GraphqlDeserializer()
Submodules¶
Classes¶
Deserializer for GraphQL API responses. |
Package Contents¶
- class ds_protocol_graphql_py_lib.serde.GraphqlDeserializer[source]¶
Bases:
ds_resource_plugin_py_lib.common.serde.deserialize.PandasDeserializerDeserializer 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 underedges, reached by the default path or arecords_pathending 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 tonode), 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
Noneto skip it. Same rule on every path.nodeis a dict: the row is the node’s fields plus the edge’s own fields (e.g.roleon a membership edge).cursorand__typenamedescribe the edge and are dropped; on a name clash the node’s value wins.nodeisnull: no record (e.g. deleted or hidden), skipped even when the edge has other fields.nullelement: skipped.Anything else (no
nodeselected, or a non-dict node): kept as is.
- _frame_from_edges(edges: list[Any]) pandas.DataFrame[source]¶
Rows from a Relay
edgeslist (see_edge_row()).
- _frame_from_list(records: list[Any], *, key: str | None = None) pandas.DataFrame[source]¶
One row per element. A list under
edgesis a Relay edge list; any other list is taken as rows unchanged (anodefield 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()).