This was pretty close, but the problem I believe is that the GraphQL endpoint is still trying to use the Film.name and Person.name predicates instead of the new name predicate. If you know you want to map a single predicate into two types then map it in the GraphQL schema using the dgraph directive:
type Film {
id: ID!
name: String! @search @dgraph(pred: "name")
}
type Person {
id: ID!
name: String! @search @dgraph(pred: "name")
}
Then for your use case you will not have to altar the DQL schema.
They were created with the “name” predicate because that is what you created them with in your DQL mutation. You could have set them with the “Person.name” predicate and the GraphQL would have worked in your first test, but not the type agnostic DQL query.
The reason why is to help separate fields by types. With Dgraph as you have found out, the same predicate can be used in multiple types, and while this may be what you want, this is most likely not what is wanted in the GraphQL API by default as then different search directives could cause a conflict. Having a broader range of predicates also helps to distribute the graph load better then having everything in a single type. The Person.name is really just a naming convention to help allow to have the same field in the multiple types in the GraphQL API. Under the hood the rewriter resolvers from GraphQL rewrite the field to the correct type-dotted notation or the mapped predicate if provided as my solution suggests doing.
Documentation: