dgraph
dgraph copied to clipboard
feat(graphql): Introducing Nested Filtering for Dgraph GraphQL API with Optimized Query Support
Description:
This merge request introduces Nested Filtering to the Dgraph GraphQL API. It allows for comprehensive filtering capabilities that span across queries, aggregations, and authorization functions.
How Does It Work?
Nested Filtering leverages Dgraph's var
block to filter nested objects and selects parent objects through inverse predicates. To enable nested filtering, you need to add the @search
directive to the nested field (edge) without any arguments.
Example:
type User {
name: String @search(by: [hash])
friends: [User] @hasInverse(field: friends) @search
}
Given the schema above, you can query users who have friends named "Ben" using the following query:
query {
queryUser(filter: { friends: { name: { eq: "Ben" } } }) {
name
}
}
Schema Validation:
If the @search
directive is added to an edge, the @hasInverse
directive must also be set on one of the referenced fields. This validation process includes handling interface fields by checking the implemented types for reverse fields.
Testing:
Testing has been conducted locally, showing approximately 50% fewer scanned nodes
Docs RFC -> https://discuss.dgraph.io/t/rfc-nested-filters-in-graphql/13560/37