Context
I’m working on a project where I need to use both GraphQL and DQL with Dgraph. I’ve set up my GraphQL schema using @hasInverse
for relationships, but I’m encountering some confusion and potential issues when trying to use DQL queries, particularly with reverse relationships.
Example GraphQL Schema
type Library {
id: ID!
name: String! @search(by: [hash])
categories: [Category] @hasInverse(field: "library")
}
type Category {
id: ID!
name: String! @search(by: [hash])
library: Library! @hasInverse(field: "categories")
parentCategory: Category @hasInverse(field: "subcategories")
subcategories: [Category] @hasInverse(field: "parentCategory")
books: [Book] @hasInverse(field: "category")
}
type Book {
id: ID!
title: String! @search(by: [term])
author: String! @search(by: [hash])
category: Category! @hasInverse(field: "books")
}
Questions
-
Compatibility: How compatible are
@hasInverse
(GraphQL) and@reverse
(DQL) when used in the same Dgraph instance? Can they coexist, or should I choose one approach exclusively? -
DQL Queries with @hasInverse: When using
@hasInverse
in GraphQL, how should I structure my DQL queries to achieve the equivalent of reverse edge queries (which would normally use the~
operator)? -
Performance Implications: Are there any performance differences between using
@hasInverse
in GraphQL vs.@reverse
in DQL, especially for complex queries or large datasets? -
Best Practices: Given that I need to use both GraphQL (for simpler queries) and DQL (for more complex operations), what’s the recommended approach for setting up my schema and relationships?
-
Mixing Approaches: Is it possible (or advisable) to use a mix of
@hasInverse
and@reverse
in the same schema? If so, how would I go about implementing this? -
Trade-offs: What are the main trade-offs to consider when choosing between
@hasInverse
and@reverse
? Are there specific use cases where one is clearly preferable over the other? -
Schema Evolution: If I start with one approach and later need to switch or incorporate the other, what kind of migration process would be involved?
I’m looking to understand the best way to structure my schema and queries to effectively use both GraphQL and DQL in Dgraph, while being aware of any limitations or incompatibilities between the two approaches. Any insights, best practices, or recommendations would be greatly appreciated.
Thank you in advance for your help!
P.S.: Reverse Edges when using both DQL and GraphQL possibly related, but still need answers after reading through it and linked discussions.