@@ -2317,7 +2317,7 @@ async def update(
2317
2317
return_old : Optional [bool ] = None ,
2318
2318
if_match : Optional [str ] = None ,
2319
2319
) -> Result [Json ]:
2320
- """Update a vertex in the graph.
2320
+ """Update an edge in the graph.
2321
2321
2322
2322
Args:
2323
2323
edge (dict): Partial or full document with the updated values.
@@ -2336,7 +2336,7 @@ async def update(
2336
2336
Returns:
2337
2337
dict: Document metadata (e.g. document id, key, revision).
2338
2338
If `return_new` or "return_old" are specified, the result contains
2339
- the document metadata in the "vertex " field and two additional fields
2339
+ the document metadata in the "edge " field and two additional fields
2340
2340
("new" and "old").
2341
2341
2342
2342
Raises:
@@ -2385,3 +2385,154 @@ def response_handler(resp: Response) -> Json:
2385
2385
raise DocumentUpdateError (resp , request , msg )
2386
2386
2387
2387
return await self ._executor .execute (request , response_handler )
2388
+
2389
+ async def replace (
2390
+ self ,
2391
+ edge : T ,
2392
+ wait_for_sync : Optional [bool ] = None ,
2393
+ keep_null : Optional [bool ] = None ,
2394
+ return_new : Optional [bool ] = None ,
2395
+ return_old : Optional [bool ] = None ,
2396
+ if_match : Optional [str ] = None ,
2397
+ ) -> Result [Json ]:
2398
+ """Replace an edge in the graph.
2399
+
2400
+ Args:
2401
+ edge (dict): Partial or full document with the updated values.
2402
+ It must contain the "_key" or "_id" field, along with "_from" and
2403
+ "_to" fields.
2404
+ wait_for_sync (bool | None): Wait until document has been synced to disk.
2405
+ keep_null (bool | None): If the intention is to delete existing attributes
2406
+ with the patch command, set this parameter to `False`.
2407
+ return_new (bool | None): Additionally return the complete new document
2408
+ under the attribute `new` in the result.
2409
+ return_old (bool | None): Additionally return the complete old document
2410
+ under the attribute `old` in the result.
2411
+ if_match (str | None): You can conditionally replace a document based on a
2412
+ target revision id by using the "if-match" HTTP header.
2413
+
2414
+ Returns:
2415
+ dict: Document metadata (e.g. document id, key, revision).
2416
+ If `return_new` or "return_old" are specified, the result contains
2417
+ the document metadata in the "edge" field and two additional fields
2418
+ ("new" and "old").
2419
+
2420
+ Raises:
2421
+ DocumentRevisionError: If precondition was violated.
2422
+ DocumentReplaceError: If replace fails.
2423
+
2424
+ References:
2425
+ - `replace-an-edge <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#replace-an-edge>`__
2426
+ """ # noqa: E501
2427
+ params : Params = {}
2428
+ if wait_for_sync is not None :
2429
+ params ["waitForSync" ] = wait_for_sync
2430
+ if keep_null is not None :
2431
+ params ["keepNull" ] = keep_null
2432
+ if return_new is not None :
2433
+ params ["returnNew" ] = return_new
2434
+ if return_old is not None :
2435
+ params ["returnOld" ] = return_old
2436
+
2437
+ headers : RequestHeaders = {}
2438
+ if if_match is not None :
2439
+ headers ["If-Match" ] = if_match
2440
+
2441
+ request = Request (
2442
+ method = Method .PUT ,
2443
+ endpoint = f"/_api/gharial/{ self ._graph } /edge/"
2444
+ f"{ self ._prep_from_doc (cast (Json , edge ))} " ,
2445
+ params = params ,
2446
+ headers = headers ,
2447
+ data = self ._doc_serializer .dumps (edge ),
2448
+ )
2449
+
2450
+ def response_handler (resp : Response ) -> Json :
2451
+ if resp .is_success :
2452
+ return self ._parse_result (self .deserializer .loads (resp .raw_body ))
2453
+ msg : Optional [str ] = None
2454
+ if resp .status_code == HTTP_PRECONDITION_FAILED :
2455
+ raise DocumentRevisionError (resp , request )
2456
+ elif resp .status_code == HTTP_NOT_FOUND :
2457
+ msg = (
2458
+ "The graph cannot be found or the edge collection is not "
2459
+ "part of the graph. It is also possible that the vertex "
2460
+ "collection referenced in the _from or _to attribute is not part "
2461
+ "of the graph or the vertex collection is part of the graph, but "
2462
+ "does not exist. Finally check that _from or _to vertex do exist."
2463
+ )
2464
+ raise DocumentReplaceError (resp , request , msg )
2465
+
2466
+ return await self ._executor .execute (request , response_handler )
2467
+
2468
+ async def delete (
2469
+ self ,
2470
+ edge : T ,
2471
+ ignore_missing : bool = False ,
2472
+ wait_for_sync : Optional [bool ] = None ,
2473
+ return_old : Optional [bool ] = None ,
2474
+ if_match : Optional [str ] = None ,
2475
+ ) -> Result [bool | Json ]:
2476
+ """Delete an edge from the graph.
2477
+
2478
+ Args:
2479
+ edge (dict): Partial or full document with the updated values.
2480
+ It must contain the "_key" or "_id" field, along with "_from" and
2481
+ "_to" fields.
2482
+ ignore_missing (bool): Do not raise an exception on missing document.
2483
+ wait_for_sync (bool | None): Wait until operation has been synced to disk.
2484
+ return_old (bool | None): Additionally return the complete old document
2485
+ under the attribute `old` in the result.
2486
+ if_match (str | None): You can conditionally replace a document based on a
2487
+ target revision id by using the "if-match" HTTP header.
2488
+
2489
+ Returns:
2490
+ bool | dict: `True` if vertex was deleted successfully, `False` if vertex
2491
+ was not found and **ignore_missing** was set to `True` (does not apply
2492
+ in transactions). Old document is returned if **return_old** is set
2493
+ to `True`.
2494
+
2495
+ Raises:
2496
+ DocumentRevisionError: If precondition was violated.
2497
+ DocumentDeleteError: If deletion fails.
2498
+
2499
+ References:
2500
+ - `remove-an-edge <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#remove-an-edge>`__
2501
+ """ # noqa: E501
2502
+ params : Params = {}
2503
+ if wait_for_sync is not None :
2504
+ params ["waitForSync" ] = wait_for_sync
2505
+ if return_old is not None :
2506
+ params ["returnOld" ] = return_old
2507
+
2508
+ headers : RequestHeaders = {}
2509
+ if if_match is not None :
2510
+ headers ["If-Match" ] = if_match
2511
+
2512
+ request = Request (
2513
+ method = Method .DELETE ,
2514
+ endpoint = f"/_api/gharial/{ self ._graph } /edge/"
2515
+ f"{ self ._prep_from_doc (cast (Json , edge ))} " ,
2516
+ params = params ,
2517
+ headers = headers ,
2518
+ )
2519
+
2520
+ def response_handler (resp : Response ) -> bool | Json :
2521
+ if resp .is_success :
2522
+ data : Json = self .deserializer .loads (resp .raw_body )
2523
+ if "old" in data :
2524
+ return cast (Json , data ["old" ])
2525
+ return True
2526
+ msg : Optional [str ] = None
2527
+ if resp .status_code == HTTP_PRECONDITION_FAILED :
2528
+ raise DocumentRevisionError (resp , request )
2529
+ elif resp .status_code == HTTP_NOT_FOUND :
2530
+ if resp .error_code == DOCUMENT_NOT_FOUND and ignore_missing :
2531
+ return False
2532
+ msg = (
2533
+ "Either the graph cannot be found, the edge collection is not "
2534
+ "part of the graph, or the edge does not exist"
2535
+ )
2536
+ raise DocumentDeleteError (resp , request , msg )
2537
+
2538
+ return await self ._executor .execute (request , response_handler )
0 commit comments