Update: I have opened this for open source discussion. And as I didn’t finish my use cases. Others could read this, fix my thoughts or add more use cases.
Use case 1
1 - Selecting films to which these directors have partnered in directing with other directors.
using var in a parent block is a cognitive jump to use it in nested blocks.
{
var(func: eq(name@en, ["Ridley Scott", "Steven Spielberg"]) ) {
name@en
director.film {
initial_release_date
name@en
worked_with : ~director.film
@filter(NOT eq(name@en, ["Ridley Scott", "Steven Spielberg"])) {
WK as uid
name@en
}
}
}
worked_withRidleyANDSteven(func: uid(WK) ) {
name@en
}
}
Result
{
"data": {
"worked_withRidleyANDSteven": [
{
"name@en": "John Woo"
},
{
"name@en": "Emir Kusturica"
},
{
"name@en": "Kátia Lund"
},
{
"name@en": "Mehdi Charef"
},
{
"name@en": "Stefano Veneruso"
},
{
"name@en": "Spike Lee"
},
{
"name@en": "George Miller"
},
{
"name@en": "Danny DeVito"
},
{
"name@en": "John Landis"
},
{
"name@en": "Joe Dante"
},
{
"name@en": "Jordan Scott"
}
]
}
}
1 -
{
query(func: eq(name@en, ["Ridley Scott", "Steven Spielberg"]) ) @filter(has(director.film)) {
# GET_US as uid
name@en
director.film @filter(gt(count(~director.film), 1)) {
initial_release_date
name@en
partnered_along_with : ~director.film
@filter(NOT eq(name@en, ["Ridley Scott", "Steven Spielberg"])) # @filter(NOT uid(GET_US))
{
name@en
}
}
}
}
2-
{ query(func: eq(name@en, ["Ridley Scott", "Steven Spielberg"])) @filter(has(director.film)) {
# GET_US as uid
uid
name@en
director.film @filter(gt(count(~director.film), 1)) {
initial_release_date
name@en
partnered_along_with : ~director.film
@filter(NOT uid(0x1693f, 0x4b928)) # @filter(NOT uid(GET_US))
{
name@en
}
}
}
}
3 - This query doesn’t work
For some reason, the GET_US
isn’t passed to the nested block.
if you use the filter @filter(NOT uid(0x1693f, 0x4b928))
it works just fine.
In the context of this query, the var GET_US
should pass the UID from the target director. e.g:
Ridley Scott
=> `partnered_along_with : ~director.film @filter(NOT uid(GET_US))`
should parse the var GET_US as
=> `partnered_along_with : ~director.film @filter(NOT uid(0x1693f))`
Steven Spielberg
=> `partnered_along_with : ~director.film @filter(NOT uid(GET_US))`
should parse the var GET_US as
=> `partnered_along_with : ~director.film @filter(NOT uid(0x4b928))`
{
query(func: eq(name@en, ["Ridley Scott", "Steven Spielberg"])) @filter(has(director.film)) {
GET_US as uid
name@en
director.film {
initial_release_date
name@en
partnered_along_with : ~director.film @filter(NOT uid(GET_US)) {
test : val(GET_US)
name@en
}
}
}
}
4 - The wise way of doing it (For THIS use case only)
is by using “count”, but this is “hackish”, using var in a parent block is a cognitive jump to use it in nested blocks.
What I did below is simple and straightforward, if I want movies where there is more than one director, then I can use “count” to check this out for me a nested block before it.
{
query(func: eq(name@en, ["Ridley Scott", "Steven Spielberg"])) @filter(has(director.film)) {
GET_US as uid
name@en
director.film @filter(gt(count(~director.film), 1)) {
initial_release_date
name@en
partnered_along_with : ~director.film {
test : val(GET_US)
name@en
}
}
}
}