Hi Dgraph team,
Now that Dgraph has a Type System, is there a plan to revisit how predicate indexes are defined?
The Problem
type Player {
name: string // want exact match here
score: int
}
type Game {
name: string // want term match here
}
<name>: string @index(exact, term) .
Player.name and Game.name are functionally independent predicates. The system may have 12 games and 1.2M players. This default approach will generate an index of at least 1.2M unnecessary terms from player names.
Workaround
A workaround is to add prefixes to predicate names:
...
type Game {
Game.name: string
}
...
<Game.name>: string @index(term) .
<Player.name>: string @index(exact) .
Although this “prefixing” works, it breaks from GraphQL convention and leads to redundancy and verbosity in queries and mutations, e.g.:
q(func:type(Player)) {
Player.name
Player.score
games {
Game.name
}
}
Proposed Solution
Ideally, we’d be able to define the indexes within the Dgraph type definition using GraphQL directives:
type Player {
name: string @index(with: "exact")
score: int
}
type Game {
name: string @index(with: "term")
}
Multiple indexes could be added as:
type Game {
name: string @index(with: ["term", "fulltext"])
}
@mrjn thoughts? Are we missing something?
Zak