Create new nodes or update existing ones with insert-or-update semantics.
Copy
Ask AI
::UpsertN({properties})
UpsertN is a traversal step that operates on an existing traversal context. The type comes from the preceding traversal (N<Type>), not from the upsert call itself. If the traversal returns existing nodes, they are updated; if no nodes are found, a new node is created.
When using the SDKs or curling the endpoint, the query name must match what is defined in the queries.hx file exactly.
QUERY UpsertPerson(name: String, age: U32) => existing <- N<Person>::WHERE(_::{name}::EQ(name)) person <- existing::UpsertN({name: name, age: age}) RETURN person
Here’s how to run the query using the SDKs or curl
Copy
Ask AI
from helix.client import Clientclient = Client(local=True, port=6969)# First call creates a new personperson = client.query("UpsertPerson", { "name": "Alice", "age": 25,})print("Created person:", person)# Subsequent calls with same data update the existing personupdated = client.query("UpsertPerson", { "name": "Alice", "age": 26,})print("Updated person:", updated)