Hi,
I’ve just completed the tour of Dgraph, and am left with some questions.
There were some examples where I tried to modify the output slightly, but could not figure out how this was done. I was hoping someone here would be able to help.
The first example is all actors in Jane Campion films that acted together in a film not directed by Jane Campion.
This also returns every actor who acted in a film by Jane Campion, and acted in one other film, since he technically acted in that film together with himself.
I tried to remove those trivial pairs, but nothing worked. My first attempt was the following:
{
coactors(func:allofterms(name@en, "Jane Campion")) @cascade {
JC_films as director.film { # JC_films = all Jane Campion's films
starting_movie: name@en
starring {
JC_actors as performance.actor { # JC_actors = all actors in all JC films
actor : name@en
actor.film {
performance.film @filter(not uid(JC_films)) {
film_together : name@en
starring @ignorereflexive {
# find a coactor who has been in some JC film
performance.actor @filter(uid(JC_actors)) {
coactor_name: name@en
}
}
}
}
}
}
}
}
}
(i.e. adding @ignorereflexive
to the relevant edge).
However, that is not a valid place for the directive.
Placing that same directive at the root (i.e. after @cascade) returns no data at all, because all actors have a path towards Jane Campion by definition.
Moving JC_actors to a separate and adding @ignorereflexive
does not help either, because alll actors have a path towards themselves.
My next attempt was: to store the name in a variable, and then just filter out duplicate names:
{
coactors(func:allofterms(name@en, "Jane Campion")) @cascade {
JC_films as director.film { # JC_films = all Jane Campion's films
starting_movie: name@en
starring {
JC_actors as performance.actor { # JC_actors = all actors in all JC films
actorNames as actor : name@en
actor.film {
performance.film @filter(not uid(JC_films)) {
film_together : name@en
starring {
# find a coactor who has been in some JC film
performance.actor @filter(uid(JC_actors) AND NOT eq(name@en, val(actorNames))) {
coactor_name: name@en
}
}
}
}
}
}
}
}
}
But that returns an error I cannot figure out how to fix.
This all brought me to the popular request of having @cascade, @normalize or @ignorerecursive
on sub-querries. I am mostly left with the question of how to achieve the effects of this without this feature.
I don’t really care about the aesthetics of the syntax, I just want the results.
Finally, in another example I get the output below.
What I don’t understand is why the predicate name@en
for the director is not included, since obviously Cherie Nowlan has a name predicate. It is how we identifiy him.
"data": {
"q": [
{
"director.film": [
{
"name@en": "Underbelly Files: The Man Who Got Away",
"name@it": "Underbelly Files: The Man Who Got Away",
"name@de": "Underbelly Files: The Man Who Got Away",
"initial_release_date": "2011-02-21T00:00:00Z"
},
{
"name@en": "Marking Time",
"name@it": "Marking Time",
"name@de": "Marking Time",
"initial_release_date": "2003-01-01T00:00:00Z"
},
{
"name@en": "Clubland",
"name@it": "Il matrimonio è un affare di famiglia",
"name@de": "Clubland",
"initial_release_date": "2007-01-21T00:00:00Z"
},
{
"name@en": "Thank God He Met Lizzie",
"name@it": "Thank God He Met Lizzie",
"name@de": "Thank God He Met Lizzie",
"initial_release_date": "1997-01-01T00:00:00Z"
}
]
}
]
}
}
Any help would be appreciated!