11__all__ = ["Graph" ]
22
33
4- from typing import Generic , Optional , Sequence , TypeVar
4+ from typing import Generic , List , Optional , Sequence , TypeVar
55
66from arangoasync .collection import EdgeCollection , VertexCollection
77from arangoasync .exceptions import (
88 EdgeDefinitionCreateError ,
9- GraphListError ,
9+ GraphPropertiesError ,
1010 VertexCollectionCreateError ,
11+ VertexCollectionDeleteError ,
12+ VertexCollectionListError ,
1113)
1214from arangoasync .executor import ApiExecutor
1315from arangoasync .request import Method , Request
@@ -74,7 +76,7 @@ async def properties(self) -> Result[GraphProperties]:
7476 GraphProperties: Properties of the graph.
7577
7678 Raises:
77- GraphListError : If the operation fails.
79+ GraphProperties : If the operation fails.
7880
7981 References:
8082 - `get-a-graph <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#get-a-graph>`__
@@ -83,7 +85,7 @@ async def properties(self) -> Result[GraphProperties]:
8385
8486 def response_handler (resp : Response ) -> GraphProperties :
8587 if not resp .is_success :
86- raise GraphListError (resp , request )
88+ raise GraphPropertiesError (resp , request )
8789 body = self .deserializer .loads (resp .raw_body )
8890 return GraphProperties (body ["graph" ])
8991
@@ -106,6 +108,56 @@ def vertex_collection(self, name: str) -> VertexCollection[T, U, V]:
106108 doc_deserializer = self ._doc_deserializer ,
107109 )
108110
111+ async def vertex_collections (self ) -> Result [List [str ]]:
112+ """Get the names of all vertex collections in the graph.
113+
114+ Returns:
115+ list: List of vertex collection names.
116+
117+ Raises:
118+ VertexCollectionListError: If the operation fails.
119+
120+ References:
121+ - `list-vertex-collections <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#list-vertex-collections>`__
122+ """ # noqa: E501
123+ request = Request (
124+ method = Method .GET ,
125+ endpoint = f"/_api/gharial/{ self ._name } /vertex" ,
126+ )
127+
128+ def response_handler (resp : Response ) -> List [str ]:
129+ if not resp .is_success :
130+ raise VertexCollectionListError (resp , request )
131+ body = self .deserializer .loads (resp .raw_body )
132+ return list (sorted (set (body ["collections" ])))
133+
134+ return await self ._executor .execute (request , response_handler )
135+
136+ async def has_vertex_collection (self , name : str ) -> Result [bool ]:
137+ """Check if the graph has the given vertex collection.
138+
139+ Args:
140+ name (str): Vertex collection mame.
141+
142+ Returns:
143+ bool: `True` if the graph has the vertex collection, `False` otherwise.
144+
145+ Raises:
146+ VertexCollectionListError: If the operation fails.
147+ """
148+ request = Request (
149+ method = Method .GET ,
150+ endpoint = f"/_api/gharial/{ self ._name } /vertex" ,
151+ )
152+
153+ def response_handler (resp : Response ) -> bool :
154+ if not resp .is_success :
155+ raise VertexCollectionListError (resp , request )
156+ body = self .deserializer .loads (resp .raw_body )
157+ return name in body ["collections" ]
158+
159+ return await self ._executor .execute (request , response_handler )
160+
109161 async def create_vertex_collection (
110162 self ,
111163 name : str ,
@@ -148,6 +200,34 @@ def response_handler(resp: Response) -> VertexCollection[T, U, V]:
148200
149201 return await self ._executor .execute (request , response_handler )
150202
203+ async def delete_vertex_collection (self , name : str , purge : bool = False ) -> None :
204+ """Remove a vertex collection from the graph.
205+
206+ Args:
207+ name (str): Vertex collection name.
208+ purge (bool): If set to `True`, the vertex collection is not just deleted
209+ from the graph but also from the database completely. Note that you
210+ cannot remove vertex collections that are used in one of the edge
211+ definitions of the graph.
212+
213+ Raises:
214+ VertexCollectionDeleteError: If the operation fails.
215+
216+ References:
217+ - `remove-a-vertex-collection <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#remove-a-vertex-collection>`__
218+ """ # noqa: E501
219+ request = Request (
220+ method = Method .DELETE ,
221+ endpoint = f"/_api/gharial/{ self ._name } /vertex/{ name } " ,
222+ params = {"dropCollection" : purge },
223+ )
224+
225+ def response_handler (resp : Response ) -> None :
226+ if not resp .is_success :
227+ raise VertexCollectionDeleteError (resp , request )
228+
229+ await self ._executor .execute (request , response_handler )
230+
151231 def edge_collection (self , name : str ) -> EdgeCollection [T , U , V ]:
152232 """Returns the edge collection API wrapper.
153233
0 commit comments