Filter with deep fields

Hello,

I’m using this generic query


`
  {
    var(func: has(proposal)){
      proposals as proposal{
      }
  }
  proposals(func: uid(proposals)){
    hash
    creator
    created_date
    content_groups{
      expand(_all_){
        expand(_all_)
      }
    }
  }
  `

that returns all the results
and I would like to filter the list where

the proposals contain at least one content_groups item that has the type ‘badge’
so basically my final object is

and I would like to filter based on the framed field
is it possible ?

You could use a @cascade(content_groups) or similar with correct syntax for:

But I am pretty sure that you cannot filter on the expand(_all_) edge to do the second cascade. I am also pretty sure that you can’t specify an edge and then use expand(_all_) as a sibling edge.


Maybe the proper way would be to create the reverse var block and then combine proposals with the other var block to get only the ones you want:

{ 
  var(func: has(proposal)) {
    proposals as proposal
  }
  var(func: type(badge)) {
    ~contents {
      badged as ~content_groups
    }
  }
  proposals(func: uid(badged)) @filter(uid(proposals)) {
    hash
    creator
    created_date
    content_groups {
      expand(_all_) {
        expand(_all_)
      }
    }
  }
}

Not confident of this syntax to copy and paste it and expect it to work, but this is the general idea.