Add other filters to expand()

Moved from GitHub dgraph/5803

Posted by MichelDiz:

Experience Report

reference: How to find relationship between two nodes? - #3 by MichelDiz

What you wanted to do

Use expand func to reduce hard typing. This increases the users experience.

{
	M as var(func: type(Person)) @filter(eq(name, 'Martin Sheen')
	O as var(func: type(Person)) @filter(eq(name, 'Oliver Stone')

	q(func: uid(O) @recurse(depth: 50, loop: true) {
		expand(User) @filter(uid(M))
	}
}

What you actually did

{
	M as var(func: type(Person)) @filter(eq(name, 'Martin Sheen')
	O as var(func: type(Person)) @filter(eq(name, 'Oliver Stone')

	q(func: uid(O) @recurse(depth: 50, loop: true) {
		friend @filter(uid(M))
		~friend @filter(uid(M))
		follows @filter(uid(M))
		~follows @filter(uid(M))
             # maybe even more edges to add (...)
	}
}

Why that wasn’t great, with examples

The only problem is that you need to hard type all possible edges to accomplish that. Using “Expand(Type)” with a filter it would catch all possible edges from the Type Definition and apply the filter as a “template”.

2 Likes