Skip to content

Commit 30a96ce

Browse files
committed
Add get method to CatalogEndpoints
1 parent 999def5 commit 30a96ce

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

graphdatascience/procedure_surface/api/catalog/catalog_endpoints.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,27 @@
1414

1515

1616
class CatalogEndpoints(ABC):
17+
@abstractmethod
18+
def get(self, graph_name: str) -> GraphV2:
19+
"""Retrieve a handle to a graph from the graph catalog.
20+
21+
Parameters
22+
----------
23+
graph_name
24+
The name of the graph.
25+
26+
Returns
27+
-------
28+
GraphV2
29+
A handle to the graph.
30+
"""
31+
pass
32+
1733
@abstractmethod
1834
def list(self, G: GraphV2 | str | None = None) -> list[GraphInfoWithDegrees]:
1935
"""List graphs in the graph catalog.
2036
21-
Args:
37+
Parameters:
2238
G (GraphV2 | str | None, optional): GraphV2 object or name to filter results.
2339
If None, list all graphs. Defaults to None.
2440
@@ -32,7 +48,7 @@ def list(self, G: GraphV2 | str | None = None) -> list[GraphInfoWithDegrees]:
3248
def drop(self, G: GraphV2 | str, fail_if_missing: bool = True) -> GraphInfo | None:
3349
"""Drop a graph from the graph catalog.
3450
35-
Args:
51+
Parameters:
3652
G (GraphV2 | str): GraphV2 object or name to drop.
3753
fail_if_missing (bool): Whether to fail if the graph is missing. Defaults to True.
3854

graphdatascience/procedure_surface/arrow/catalog/catalog_arrow_endpoints.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def __init__(
5252
protocol_version = ProtocolVersionResolver(query_runner).resolve()
5353
self._project_protocol = ProjectProtocol.select(protocol_version)
5454

55+
def get(self, graph_name: str) -> GraphV2:
56+
if not self.list(graph_name):
57+
raise ValueError(f"A graph with name '{graph_name}' does not exist in the catalog.")
58+
return get_graph(graph_name, self._arrow_client)
59+
5560
def list(self, G: GraphV2 | str | None = None) -> list[GraphInfoWithDegrees]:
5661
graph_name: str | None = None
5762
if isinstance(G, GraphV2):

graphdatascience/procedure_surface/cypher/catalog_cypher_endpoints.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def __init__(self, cypher_runner: Neo4jQueryRunner, arrow_client: GdsArrowClient
3333
self.cypher_runner = cypher_runner
3434
self._arrow_client = arrow_client
3535

36+
def get(self, graph_name: str) -> GraphV2:
37+
if not self.list(graph_name):
38+
raise ValueError(f"A graph with name '{graph_name}' does not exist in the catalog.")
39+
return get_graph(graph_name, self.cypher_runner)
40+
3641
def list(self, G: GraphV2 | str | None = None) -> list[GraphInfoWithDegrees]:
3742
graph_name = G if isinstance(G, str) else G.name() if G is not None else None
3843
params = CallParameters(graphName=graph_name) if graph_name else CallParameters()

0 commit comments

Comments
 (0)