@@ -2307,3 +2307,81 @@ def response_handler(resp: Response) -> Json:
23072307 raise DocumentInsertError (resp , request , msg )
23082308
23092309 return await self ._executor .execute (request , response_handler )
2310+
2311+ async def update (
2312+ self ,
2313+ edge : T ,
2314+ wait_for_sync : Optional [bool ] = None ,
2315+ keep_null : Optional [bool ] = None ,
2316+ return_new : Optional [bool ] = None ,
2317+ return_old : Optional [bool ] = None ,
2318+ if_match : Optional [str ] = None ,
2319+ ) -> Result [Json ]:
2320+ """Update a vertex in the graph.
2321+
2322+ Args:
2323+ edge (dict): Partial or full document with the updated values.
2324+ It must contain the "_key" or "_id" field, along with "_from" and
2325+ "_to" fields.
2326+ wait_for_sync (bool | None): Wait until document has been synced to disk.
2327+ keep_null (bool | None): If the intention is to delete existing attributes
2328+ with the patch command, set this parameter to `False`.
2329+ return_new (bool | None): Additionally return the complete new document
2330+ under the attribute `new` in the result.
2331+ return_old (bool | None): Additionally return the complete old document
2332+ under the attribute `old` in the result.
2333+ if_match (str | None): You can conditionally update a document based on a
2334+ target revision id by using the "if-match" HTTP header.
2335+
2336+ Returns:
2337+ dict: Document metadata (e.g. document id, key, revision).
2338+ If `return_new` or "return_old" are specified, the result contains
2339+ the document metadata in the "vertex" field and two additional fields
2340+ ("new" and "old").
2341+
2342+ Raises:
2343+ DocumentUpdateError: If update fails.
2344+
2345+ References:
2346+ - `update-an-edge <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#update-an-edge>`__
2347+ """ # noqa: E501
2348+ params : Params = {}
2349+ if wait_for_sync is not None :
2350+ params ["waitForSync" ] = wait_for_sync
2351+ if keep_null is not None :
2352+ params ["keepNull" ] = keep_null
2353+ if return_new is not None :
2354+ params ["returnNew" ] = return_new
2355+ if return_old is not None :
2356+ params ["returnOld" ] = return_old
2357+
2358+ headers : RequestHeaders = {}
2359+ if if_match is not None :
2360+ headers ["If-Match" ] = if_match
2361+
2362+ request = Request (
2363+ method = Method .PATCH ,
2364+ endpoint = f"/_api/gharial/{ self ._graph } /edge/"
2365+ f"{ self ._prep_from_doc (cast (Json , edge ))} " ,
2366+ params = params ,
2367+ headers = headers ,
2368+ data = self ._doc_serializer .dumps (edge ),
2369+ )
2370+
2371+ def response_handler (resp : Response ) -> Json :
2372+ if resp .is_success :
2373+ return self ._parse_result (self .deserializer .loads (resp .raw_body ))
2374+ msg : Optional [str ] = None
2375+ if resp .status_code == HTTP_PRECONDITION_FAILED :
2376+ raise DocumentRevisionError (resp , request )
2377+ elif resp .status_code == HTTP_NOT_FOUND :
2378+ msg = (
2379+ "The graph cannot be found or the edge collection is not "
2380+ "part of the graph. It is also possible that the vertex "
2381+ "collection referenced in the _from or _to attribute is not part "
2382+ "of the graph or the vertex collection is part of the graph, but "
2383+ "does not exist. Finally check that _from or _to vertex do exist."
2384+ )
2385+ raise DocumentUpdateError (resp , request , msg )
2386+
2387+ return await self ._executor .execute (request , response_handler )
0 commit comments