Dgraph DQL Tour

Basic

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, whether or not they own a pet.

{
  michael_friends_with_pets(func: allofterms(name@., "Michael")) {
    name
    age
    friend {
      name@.
      owns_pet
    }
  }
}

With the @cascade directive, friends of Michael that don’t own a pet are not included in the result.

{
  michael_friends_with_pets(func: allofterms(name@., "Michael")) @cascade {
    name
    age
    friend {
      name@.
      owns_pet
    }
  }
}

You can read more about @cascade directive in our documentation site: https://dgraph.io/docs/query-language/#cascade-directive

2.14 Cascade