tron
October 20, 2020, 4:54pm
1
Suppose my DQL schema has two nodes with a name
predicate…
type User {
name
}
type Pet {
name
}
Many examples in the Dgraph documentation define a single index that is shared between types:
name: string @index(hash) .
So how would I declare a hash
index for User.name
and a term
index for Pet.name
? My first thought was to try this…
User.name: string @index(hash) .
Pet.name: string @index(term) .
…but the /alter
endpoint returns an error:
Schema does not contain a matching predicate for field name in type User
MichelDiz
(Michel Diz)
October 20, 2020, 5:28pm
2
Cuz your schema needs to be like this
type User {
User.name
}
type Pet {
Pet.name
}
User.name: string @index(hash) .
Pet.name: string @index(term) .
DQL Schema is different from GraphQL Schema. In GraphQL this pattern comes automatically, in DQL you have to do it manually.
tron
October 20, 2020, 5:47pm
3
Thank you, @MichelDiz . That worked perfectly.
For anyone else that may find this post helpful, it’s noteworthy to point out that the above schema doesn’t require User.name
as the predicate in queries—you just use name
:
{
user(func: type(User)) {
name // User.name doesn't work here
}
}
amaster507
(Anthony Master)
October 20, 2020, 6:00pm
4
I think something is off here then. If I want to access my GraphQL schema (without any mapped predicates) values I have to use the type dotted notation in DQL. In other words, for me it is opposite:
{
user(func: type(User)) {
User.name // name doesn't work here
}
}
tron
October 20, 2020, 6:12pm
5
I think something is off here then.
You’re right, I made a mistake. I inadvertently created a user on the mutate tab of Ratel like this:
{
set {
_:user <dgraph.type> "User" .
_:user <name> "Tron" .
}
}
This is what I should have done:
{
set {
_:user <dgraph.type> "User" .
_:user <User.name> "Tron" .
}
}
Sorry for the confusion. I’m still trying to get my Dgraph sea legs.
amaster507
(Anthony Master)
October 20, 2020, 6:23pm
6
oh, yes, I imported 7 million quads of data and then realized I made a similar mistake
It is good to see someone else using both graphql and DQL together. I will watch you for any future topics.