Memgraph integration fixes (#991)

<!-- .github/pull_request_template.md -->

## Description
Created a fix for Memgraph integration where the query silently fails in
relationship creation if nodes don't exist.

## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin.

---------

Co-authored-by: github-actions[bot] <github-actions@users.noreply.github.com>
Co-authored-by: hajdul88 <52442977+hajdul88@users.noreply.github.com>
Co-authored-by: Boris <boris@topoteretes.com>
This commit is contained in:
Matea Pesic 2025-07-16 15:01:41 +02:00 committed by GitHub
parent 7f62daebd2
commit a06b3fc7e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -381,12 +381,19 @@ class MemgraphAdapter(GraphDBInterface):
The result of the edge addition operation, including relationship details.
"""
exists = await asyncio.gather(self.has_node(str(from_node)), self.has_node(str(to_node)))
if not all(exists):
return None
serialized_properties = self.serialize_properties(edge_properties or {})
query = dedent(
f"""\
MATCH (from_node {{id: $from_node}}),
(to_node {{id: $to_node}})
WHERE from_node IS NOT NULL AND to_node IS NOT NULL
MERGE (from_node)-[r:{relationship_name}]->(to_node)
ON CREATE SET r += $properties, r.updated_at = timestamp()
ON MATCH SET r += $properties, r.updated_at = timestamp()