I’m completely new to graph databases (not to graphs, though), but I’ve been spending a bit of time recently tinkering and learning about dgraph and I’ve come across a query in the Tour of Dgraph I don’t quite follow, most likely because I’m missing something fundamental.
{
PJ as var(func:allofterms(name@en, "Peter Jackson")) @normalize @cascade {
F as director.film
}
peterJ(func: uid(PJ)) @normalize @cascade {
name : name@en
actor.film {
performance.film @filter(uid(F)) {
film_name: name@en
}
performance.character {
character: name@en
}
}
}
}
The way I understand it is the first query will match all nodes that match the allofterms(...)
function results. This will give me a list of uid
s of all Peter Jackson nodes (or at least the one matching the PJ query)
Now, the next query (peterJ
) is then “run” for each of the matched node (uid(PJ)
) …the query “follows” the actor.film
edge and this is where I get really confused: actor.film
edge will lead to a list of (presumably film) nodes, but how do I know that those matched nodes might have performance.film
and performance.character
predicates?
I did a quick query for schema in the playground but I’m none the wiser. How do the authors of the tour know there will be these predicates? Is there a way to discover them?
I assume actor.film
will “lead” to (match) a film node, so it would never occur to me a film node would have an edge to another film node (?) alas it’s possible. Either way, how do I know what predicates the films might have?
I’m sure I’m missing something fundamental and my mental model is not quite right. I’d appreciate if someone could shed some light on this.