Dgraph OR cascadeFields results

I am wondering if there is a way to filter multiple cascade fields via an OR filter rather than an and operation. being able to do something like below.

query {
  queryUser(first:0, offset:0) @cascade(fields: [jobNotes, accountNotes], operator: OR){
    id
    jobNotes(filter:{name:{regexp:"/.*ben.*/"}}) {
      name
    }
    accountNotes(filter:{name:{regexp:"/.*ben.*/"}}) {
      name
    }
  }
}

Is this anyway to achieve this? or is there a plan for something like this?

Currently, using OR on cascade fields is not possible. We, currently don’t have any plan to support this. We can accept this as a feature request if this is a valid use case.

It seems to me that types of jobNotes and accountNotes have some common fields and are similar in nature. If that is the case, you may try defining a common interface for accountNotes and jobNotes containing all common fields.

Documentation for Interfaces: https://dgraph.io/docs/graphql/schema/types/#interfaces

Thanks rajas we have used interfaces already, this is just a sample example, in our use case the fields can be of any type/depth.
It is mainly for trying to retrieve as small a dataset as required in one go. In dql you may store in a variable. Whereas in the graphql layer I would need to run to queries and merge the results myself, increase the load/amount of data potentially transferred between app and dgraph.

Adding support for GraphQL nested filters is a feature requested by multiple Users recently. This has also been added to our 2021 Roadmap and we will be supporting it in coming quarters.

The feature for OR with @cascade fields would then not be needed and a nested filter applied to queryUser will suffice your use case.

You may read more about the feature request for nested filters in the following posts:

  1. Proposal Nested Object Filters for GraphQL rewritten as var blocks in DQL
  2. Filter on non-scalar fields or relations (Types)
  3. GraphQL: Connected filter on non-scalar list element fields
1 Like