Skip to content

Commit e56929e

Browse files
committed
Adding "has" for vertex collections
1 parent d969ce6 commit e56929e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

arangoasync/graph.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,38 @@ def response_handler(resp: Response) -> None:
233233

234234
await self._executor.execute(request, response_handler)
235235

236+
async def has_vertex(
237+
self,
238+
vertex: str | Json,
239+
allow_dirty_read: bool = False,
240+
if_match: Optional[str] = None,
241+
if_none_match: Optional[str] = None,
242+
) -> Result[bool]:
243+
"""Check if the vertex exists in the graph.
244+
245+
Args:
246+
vertex (str | dict): Document ID, key or body.
247+
Document body must contain the "_id" or "_key" field.
248+
allow_dirty_read (bool): Allow reads from followers in a cluster.
249+
if_match (str | None): The document is returned, if it has the same
250+
revision as the given ETag.
251+
if_none_match (str | None): The document is returned, if it has a
252+
different revision than the given ETag.
253+
254+
Returns:
255+
`True` if the document exists, `False` otherwise.
256+
257+
Raises:
258+
DocumentRevisionError: If the revision is incorrect.
259+
DocumentGetError: If retrieval fails.
260+
""" # noqa: E501
261+
return await self.vertex_collection(Collection.get_col_name(vertex)).has(
262+
vertex,
263+
allow_dirty_read=allow_dirty_read,
264+
if_match=if_match,
265+
if_none_match=if_none_match,
266+
)
267+
236268
async def vertex(
237269
self,
238270
vertex: str | Json,

tests/test_graph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ async def test_vertex_collections(db, docs, bad_graph):
174174
with pytest.raises(DocumentDeleteError):
175175
assert await graph.delete_vertex(v1["_id"])
176176

177+
# Check has method
178+
assert await graph.has_vertex(v1) is False
179+
assert await graph.has_vertex(v2["_id"]) is True
180+
177181

178182
async def test_edge_collections(db, bad_graph):
179183
# Test errors

0 commit comments

Comments
 (0)