Sceat commented :
Hum Custom blocks seems pretty handy, great proposal ! it would also go nicely with unwinds.
I didn’t even noticed that upsert doesn’t support variables as in the javascript client it seems i can set variables on the query and the mutations
Regarding the unwind statement in cypher it allows to take anything iterable and use it in a graph sequence
UNWIND [1, 2, 3] AS num
with this we have the variable num that represent each value of the array but in sequence, so on the first node found the value will be 1 then on the second node it will be 2 etc…
If one wants to upsert an array of users based on their name, the unwind operation allow to write a compact query
upsert {
// not sure where you put the bloc (your forum link is broken)
// so let's say we put it there
var() {
user_data AS UNWIND [{name: 'Alice', age: 20}, {name: 'Bob', age: 25}]
}
query {
user as var(func: eq(name, user_data.name))
}
mutation {
set {
uid(user) <age> val(user_data.age) .
}
}
}
// the above would set both Alice and Bob with their respective ages
without unwind you actually have to do the following
upsert {
query($alice: string, $bob: string) {
alice as var(func: eq(name, $alice))
bob as var(func: eq(name, $bob))
}
mutation($alice_age: int, $bob_age: int) {
set {
uid(alice) <age> val($alice_age) .
uid(bob) <age> val($bob_age) .
}
}
}
// it works but in case you have 100 users your generated query is a bit insane