-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Check if resolvedarea/querylang/varsIssues related to queries with GraphQL variablesIssues related to queries with GraphQL variableskind/enhancementSomething could be better.Something could be better.status/needs-attentionThis issue needs more eyes on it, more investigation might be required before accepting/rejecting itThis issue needs more eyes on it, more investigation might be required before accepting/rejecting it
Description
What you wanted to do
Dynamically use external datas inside queries by unwinding arrays
with unwind:
upsert {
query($names: [string], $ages: [int]) {
unwind $names as user_name
unwind $ages as user_age
user as var(func: eq(name, user_name))
}
mutation {
set {
uid(user) <age> val(user_age) .
}
}
}
This would map each value in the array names and ages to the current Dgraph map index so that the first found user receive user_name from names[0] and so on.
It would be even better to support $users: [user] to be able to shorthand to
unwind $users as an_user
user as var(func: eq(name, an_user.name))
without unwind: (current behavior)
upsert {
query($name_1: string!, $name_2: string!) {
user_1 as var(func: eq(name, $name_1))
user_2 as var(func: eq(name, $name_2))
}
mutation($age_1: int!, $age_2: int!) {
set {
uid(user_1) <age> $age_1 .
uid(user_2) <age> $age_2 .
}
}
}
What you actually did
Thinking about manually unwinding my datas by interpolating as many query lines as needed and propagating variables with dynamic aliases like in the without unwind exemple
Why that wasn't great
That makes the query extra heavy and insanely verbose for big arrays of nodes
Any external references to support your case
Metadata
Metadata
Assignees
Labels
Check if resolvedarea/querylang/varsIssues related to queries with GraphQL variablesIssues related to queries with GraphQL variableskind/enhancementSomething could be better.Something could be better.status/needs-attentionThis issue needs more eyes on it, more investigation might be required before accepting/rejecting itThis issue needs more eyes on it, more investigation might be required before accepting/rejecting it