Skip to content

Add support for datas UNWIND #5165

@Sceat

Description

@Sceat

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

UNWIND in Cypher

Metadata

Metadata

Assignees

No one assigned

    Labels

    Check if resolvedarea/querylang/varsIssues related to queries with GraphQL variableskind/enhancementSomething could be better.status/needs-attentionThis issue needs more eyes on it, more investigation might be required before accepting/rejecting it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions