Skip to content

Commit c276abf

Browse files
jfrench9claude
andauthored
Consolidate graph operations into unified module and migrate report handling (#91)
## Summary Refactors the client SDK by consolidating scattered API operations (backup, restore, materialize, subgraph management, tier upgrades) into a unified `graph_operations` module, and migrates report handling from a standalone `ReportClient` into `LedgerClient`. ## Key Changes ### Unified Graph Operations Module - **Consolidated API layer**: Replaced separate `api/backup/`, `api/materialize/`, and `api/subgraphs/` directories with a single `api/graph_operations/` module containing: - `op_create_backup` — backup creation - `op_restore_backup` — backup restoration - `op_materialize` — graph materialization - `op_create_subgraph` — subgraph creation - `op_delete_subgraph` — subgraph deletion - `op_upgrade_tier` — tier upgrade operations - All operations now follow a consistent `op_*` naming convention, improving discoverability and maintainability. ### Client Consolidation - **Removed `MaterializationClient`**: Its responsibilities have been absorbed into `GraphClient`, which now serves as the single entry point for all graph-related operations. - **Migrated report handling to `LedgerClient`**: Removed `ReportClient` references and implemented report functionality directly in `LedgerClient`. - Updated `facade.py` and `clients/__init__.py` to reflect the simplified client hierarchy. ### Model Simplification - Renamed and streamlined models to match the operation-centric pattern: - `delete_subgraph_request.py` → `delete_subgraph_op.py` - `backup_restore_request.py` → `restore_backup_op.py` - `materialize_response_limit_check_type_0.py` → `upgrade_tier_op.py` - Removed now-redundant response models (`delete_subgraph_response`, `materialize_request`, `materialize_response`, `materialize_status_response`). - Updated `operation_envelope.py` to accommodate the new operation types. ## Breaking Changes ⚠️ **This is a breaking change for consumers of the SDK.** - `MaterializationClient` has been removed — callers must use `GraphClient` instead. - `ReportClient` references removed — use `LedgerClient` for report operations. - Several model classes have been renamed or removed; any direct imports of the old models will break. - API module paths have changed (`api.backup.*`, `api.materialize.*`, `api.subgraphs.create_subgraph`, `api.subgraphs.delete_subgraph` are all removed). ## Testing Notes - `test_materialization_client.py` has been updated to reflect the new client structure and operation patterns. - `test_extensions.py` updated for model/import changes. - Verify that all graph operations (backup, restore, materialize, subgraph CRUD, tier upgrade) function correctly end-to-end after the consolidation. - Confirm `LedgerClient` report handling works as expected in place of the former `ReportClient`. ## Infrastructure Considerations - Downstream services and CI pipelines that depend on the removed clients or old import paths will need to be updated. - Documentation and SDK usage examples should be revised to reference the new `graph_operations` module and consolidated client interfaces. - The net reduction of ~1,200 lines indicates significant deduplication, which should reduce long-term maintenance burden. --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `feature/graph-ops` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents 30a34cc + 1801f28 commit c276abf

32 files changed

Lines changed: 2267 additions & 4035 deletions

‎robosystems_client/api/backup/create_backup.py‎

Lines changed: 0 additions & 445 deletions
This file was deleted.

‎robosystems_client/api/backup/restore_backup.py‎

Lines changed: 0 additions & 479 deletions
This file was deleted.
File renamed without changes.
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
from http import HTTPStatus
2+
from typing import Any, cast
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.backup_create_request import BackupCreateRequest
10+
from ...models.http_validation_error import HTTPValidationError
11+
from ...models.operation_envelope import OperationEnvelope
12+
from ...models.operation_error import OperationError
13+
from ...types import UNSET, Response, Unset
14+
15+
16+
def _get_kwargs(
17+
graph_id: str,
18+
*,
19+
body: BackupCreateRequest,
20+
idempotency_key: None | str | Unset = UNSET,
21+
) -> dict[str, Any]:
22+
headers: dict[str, Any] = {}
23+
if not isinstance(idempotency_key, Unset):
24+
headers["Idempotency-Key"] = idempotency_key
25+
26+
_kwargs: dict[str, Any] = {
27+
"method": "post",
28+
"url": "/v1/graphs/{graph_id}/operations/create-backup".format(
29+
graph_id=quote(str(graph_id), safe=""),
30+
),
31+
}
32+
33+
_kwargs["json"] = body.to_dict()
34+
35+
headers["Content-Type"] = "application/json"
36+
37+
_kwargs["headers"] = headers
38+
return _kwargs
39+
40+
41+
def _parse_response(
42+
*, client: AuthenticatedClient | Client, response: httpx.Response
43+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
44+
if response.status_code == 202:
45+
response_202 = OperationEnvelope.from_dict(response.json())
46+
47+
return response_202
48+
49+
if response.status_code == 400:
50+
response_400 = OperationError.from_dict(response.json())
51+
52+
return response_400
53+
54+
if response.status_code == 401:
55+
response_401 = cast(Any, None)
56+
return response_401
57+
58+
if response.status_code == 403:
59+
response_403 = cast(Any, None)
60+
return response_403
61+
62+
if response.status_code == 404:
63+
response_404 = OperationError.from_dict(response.json())
64+
65+
return response_404
66+
67+
if response.status_code == 409:
68+
response_409 = OperationError.from_dict(response.json())
69+
70+
return response_409
71+
72+
if response.status_code == 422:
73+
response_422 = HTTPValidationError.from_dict(response.json())
74+
75+
return response_422
76+
77+
if response.status_code == 429:
78+
response_429 = cast(Any, None)
79+
return response_429
80+
81+
if response.status_code == 500:
82+
response_500 = cast(Any, None)
83+
return response_500
84+
85+
if client.raise_on_unexpected_status:
86+
raise errors.UnexpectedStatus(response.status_code, response.content)
87+
else:
88+
return None
89+
90+
91+
def _build_response(
92+
*, client: AuthenticatedClient | Client, response: httpx.Response
93+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
94+
return Response(
95+
status_code=HTTPStatus(response.status_code),
96+
content=response.content,
97+
headers=response.headers,
98+
parsed=_parse_response(client=client, response=response),
99+
)
100+
101+
102+
def sync_detailed(
103+
graph_id: str,
104+
*,
105+
client: AuthenticatedClient,
106+
body: BackupCreateRequest,
107+
idempotency_key: None | str | Unset = UNSET,
108+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
109+
"""Create Backup
110+
111+
Create a backup of the graph database (async).
112+
113+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
114+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
115+
116+
Args:
117+
graph_id (str):
118+
idempotency_key (None | str | Unset):
119+
body (BackupCreateRequest): Request model for creating a backup.
120+
121+
Raises:
122+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123+
httpx.TimeoutException: If the request takes longer than Client.timeout.
124+
125+
Returns:
126+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
127+
"""
128+
129+
kwargs = _get_kwargs(
130+
graph_id=graph_id,
131+
body=body,
132+
idempotency_key=idempotency_key,
133+
)
134+
135+
response = client.get_httpx_client().request(
136+
**kwargs,
137+
)
138+
139+
return _build_response(client=client, response=response)
140+
141+
142+
def sync(
143+
graph_id: str,
144+
*,
145+
client: AuthenticatedClient,
146+
body: BackupCreateRequest,
147+
idempotency_key: None | str | Unset = UNSET,
148+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
149+
"""Create Backup
150+
151+
Create a backup of the graph database (async).
152+
153+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
154+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
155+
156+
Args:
157+
graph_id (str):
158+
idempotency_key (None | str | Unset):
159+
body (BackupCreateRequest): Request model for creating a backup.
160+
161+
Raises:
162+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
163+
httpx.TimeoutException: If the request takes longer than Client.timeout.
164+
165+
Returns:
166+
Any | HTTPValidationError | OperationEnvelope | OperationError
167+
"""
168+
169+
return sync_detailed(
170+
graph_id=graph_id,
171+
client=client,
172+
body=body,
173+
idempotency_key=idempotency_key,
174+
).parsed
175+
176+
177+
async def asyncio_detailed(
178+
graph_id: str,
179+
*,
180+
client: AuthenticatedClient,
181+
body: BackupCreateRequest,
182+
idempotency_key: None | str | Unset = UNSET,
183+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
184+
"""Create Backup
185+
186+
Create a backup of the graph database (async).
187+
188+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
189+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
190+
191+
Args:
192+
graph_id (str):
193+
idempotency_key (None | str | Unset):
194+
body (BackupCreateRequest): Request model for creating a backup.
195+
196+
Raises:
197+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
198+
httpx.TimeoutException: If the request takes longer than Client.timeout.
199+
200+
Returns:
201+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
202+
"""
203+
204+
kwargs = _get_kwargs(
205+
graph_id=graph_id,
206+
body=body,
207+
idempotency_key=idempotency_key,
208+
)
209+
210+
response = await client.get_async_httpx_client().request(**kwargs)
211+
212+
return _build_response(client=client, response=response)
213+
214+
215+
async def asyncio(
216+
graph_id: str,
217+
*,
218+
client: AuthenticatedClient,
219+
body: BackupCreateRequest,
220+
idempotency_key: None | str | Unset = UNSET,
221+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
222+
"""Create Backup
223+
224+
Create a backup of the graph database (async).
225+
226+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
227+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
228+
229+
Args:
230+
graph_id (str):
231+
idempotency_key (None | str | Unset):
232+
body (BackupCreateRequest): Request model for creating a backup.
233+
234+
Raises:
235+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
236+
httpx.TimeoutException: If the request takes longer than Client.timeout.
237+
238+
Returns:
239+
Any | HTTPValidationError | OperationEnvelope | OperationError
240+
"""
241+
242+
return (
243+
await asyncio_detailed(
244+
graph_id=graph_id,
245+
client=client,
246+
body=body,
247+
idempotency_key=idempotency_key,
248+
)
249+
).parsed

0 commit comments

Comments
 (0)