Reverse Edges when using both DQL and GraphQL

I have a single instance of Dgraph that I use for both DQL and GraphQL queries, and I define both schema types. In general this works well, but i have an issue making reverse edges work nicely across both.

In DQL it is simple, i can link TypeA to TypeB with a TypeA.owns edge, with an @reverse directive. This results in a single predicate on TypeA, and i can navigate from TypeB to TypeA with ~TypeA.owns query.

For the GraphQL schema, I can reuse the outbound edge predicate with owns: [TypeB] on TypeA, as it reuses the existing TypeA.owns predicate from DQL schema. However, for the reverse edge it seems I have to add an extra predicate to my schema. ~owns: [TypeB] @dgraph(pred: "~TypeA.owns") is invalid syntax as ~ is not allowed.

My current solution is to have owns: [TypeB] @hasInverse(field: ownedBy) on TypeA and ownedBy: [TypeA] on TypeB. I’d prefer to avoid this as it is simpler to use the owns and ~owns construct in DQL, and leave dgraph to manage the creation of reverse edges etc. Is there some way to acheive this without the extra predicate?


Why not just use the DQL reverse method and use Custom query on GraphQL instead?

Thanks, I looked at the docs for Custom Queries but I cant see how I could use this to redirect one GraphQL predicate to a ~Type.predicate from DQL, do you have an example of how to do this? I think an entire DQL query block to retreive a single predicate per node wouldnt be performant enough in this case.

This example isn’t precise or tested. I did based on my own intuition.

type Query {
  queryUserSomething: [SomethingCount] @custom(dql: """
	query {
		queryUserTweetCounts(func: type(Something)) {

Not sure what you mean. You mentioned GraphQL, so I thought you were using GraphQL. In that case, the example above would fit.

Well, there isn’t another way. I haven’t done it. And as both inverse and reverse are completely different approaches, I think it will be hard to sync them.

For future people seeing this thread, what I was attempting to do is possible, see the answers in these threads: hasInverse and how its different from using @reverse on predicates - #3 by RJKeevil Real inverse relation on GraphQL schema - #12 by pawan