Docs(GraphQL): document inverse relationships in Dgraph GraphQL#738
Conversation
Added documentation on defining bidirectional relationships in Dgraph GraphQL schemas, detailing two approaches: Dual Predicates and Reverse Index, along with their tradeoffs, usage examples, and migration guidance.
There was a problem hiding this comment.
I think this is an very helpful addition to the docs.
When I was working on a Postgres schema conversion for a POC, it wasn't clear to me which to use when I converted the DQL schema I first created to a 'canonical' GraphQL representation. I did the first pass using @dgraph(pred: "~...") but then worried I by doing so I was leaning on legacy syntax and switched to @hasInverse.
IIRC I even asked opus to search the docs to explain the difference and what the preferred for was, and it wasn't able to provide a clear answer, besides suggesting @hasInverse was newer and therefore more likely to be idiomatic.
I didn't have any idea by doing so I was committing to having the GraphQL API layer be solely responsible for maintaining consistency, and that any DQL mutations I applied after would have to explicitly apply the reverse relationship as a separate predicate.
Being a little more careful I might have noticed lack of reverse relationships in the DQL schema created from the GraphQL -- I even saved the json of the DQL schema generated from the GraphQL as a fixture and used it in a comparison test -- but it didn't occur to me that it would be something I should check.
Added documentation on defining bidirectional relationships in Dgraph GraphQL schemas, detailing two approaches: Dual Predicates and Reverse Index, along with their tradeoffs, usage examples, and migration guidance.