Cascade

The @cascade directive removes any nodes that don’t have all matching edges in the query.

Another use is to remove nodes where a filter inside a block returns no results.

In the query below, Dgraph returns all Michael’s friends, and only the friends of friends who are over 27.

{
  michael_friends(func: allofterms(name, "Michael")) {
    name
    age
    friend {
      [email protected]
      friend @filter(ge(age, 27)) {
        [email protected]
        age
      }
    }
  }
}

With the @cascade directive, friends of Michael that don’t have friends who are over 27 are not included in the result.

{
  michael_friends(func: allofterms(name, "Michael")) @cascade {
    name
    age
    friend {
      [email protected]
      friend @filter(ge(age, 27)) {
        [email protected]
        age
      }
    }
  }
}
Endpoint: /query
Response