ok that’s good enough.
Another question abiut the gap between GQL and DQL,
when I use, for example, the @hasInverse directive and look in Ratel on the schema, I can’t see the @reverse index under the relvante predicate.
Can you tell why it doesn’t be reflected?
This is done purposefully. @hasInverse
is not the equivalent to adding the @reverse
directive in DQL. On the graphql schema, the @hasInverse
directive creates logic in the resolvers to add/update/delete the inverse edge of the specified type. There is more to the underlying reasoning behind this but overall it is to allow for better type notatation predicate control. In DQL a single predicate can be applied between two types, but in GQL, if a Post
Type has an author
predicate and a Author
Type has a hasPosts
predicate, and they are linked with the @hasInverse
, then the logic links Post.author <-> Author.hasPosts
. In DQL this would be controlled without really specifying the edge on the opposite and assigning the @reverse
which allows you to query with the ~
syntax such as ~author
This seems to be a common topic here in this community. @core-devs Is there any work for documentation that explains more of the differences like this between DQL and GQL? So far all I am seeing is:
And the docs for @hasInverse and @reverse don’t really help explain why the one is not equivalent to the other:
The documentation has a section on GraphQL - DQL interoperability where we try to capture what would be useful for a developer.
You don’t see @reverse in Ratel on the DQL schema when you have used @hasInverse in GQL simply because we are not using @reverse to implement the @hasInverse behavior.
I’d like to better understand your developer use case here so we can update the documentation.
We would like the doc to be use case oriented instead of explaining a design decision.
What are you trying to achieve that led you to use @hasInverse in GQL and try DQL queries on the same data? That would help improve the “GraphQL - DQL interoperability” section. (You can push a PR to the doc too).
@amaster507 explained it well
in GQL if you have
Post --has_author–> Author
and
Author --writes–> Posts
Author --likes–> Posts
Author --reviews–> Posts
When you create a Post with an Author, what is the “reverse” link to create: ‘writes’ ‘likes’ or ‘reviews’.
You need a way to specify that the reverse of “has_author” is “writes”. The “simple” reverse predicate in DQL is not a solution.
That said, you can use the @dgraph predicate as explained in GraphQL on Existing Dgraph - GraphQL dql to tweak the mapping between GQL and DQL. But that is an advanced use case only if the standard approach cannot cover what you want to do.