Hi there
So let me walk you thru Moredata/2
:
First, here’s the schema:
# Define Directives and index
director.film: [uid] @reverse .
actor.film: [uid] @count .
genre: [uid] @reverse .
initial_release_date: dateTime @index(year) .
name: string @index(exact, term) @lang .
starring: [uid] .
performance.film: [uid] .
performance.character_note: string .
performance.character: [uid] .
performance.actor: [uid] .
performance.special_performance_type: [uid] .
type: [uid] .
# Define Types
type Person {
name
director.film
actor.film
}
type Movie {
name
initial_release_date
genre
starring
}
type Genre {
name
}
type Performance {
performance.film
performance.character
performance.actor
}
I see from the schema that “Person Type” has name
and director.film
(and actor.film
also) but I don’t see how it tells me that director.film
is a “Movie Type“.
You are right. If you look at this
director.film: [uid] @reverse
You see its type is a uid
. Meaning it is any node. Usually we like typed nodes, so let’s only consider that. Thus a bit of leap in inference is required. Dgraph is fundamentally untyped in its core. You could of course assign a Person-typed node to director.film
. But don’t do that.
I can guess that genre
edge is of type Genre
because of the names but how from the schema ?
So what I’d do is look at starring
:
starring: [uid] .
Nothing in this schema tells us that it’s supposed to be a node that is typed by Person
. However as a schema designer you would have that in mind.
The paradigm we prefer in Dgraph is to treat it as a dynamically typed language. You can always enforce that starring
is a Person
in your queries:
q(func: type(Movie)) {
name
starring @filter(type(Person)) {
name
}
}
I’ll discuss why this was chosen in the next post.
Of course if you run the query above, nothing will show up, because starring
is not a Person
. Rather it’s a Performance
.
How can I get “nodes reached via that edge” and know it is a performance?
You get the nodes reached via that edge by putting it in your query. And you know its type by using the <dgraph.type>
field:
q(func: type(Movie)) {
starring { # adding this field queries nodes reached by the edge `starring`
<dgraph.type> # tells you the type that the nodes that are in `starrng` is
}
}
So you’re right, a lot of it is guesswork/intelligent inference.