Cascade Directive with Pagination produces unexpected results

No, there is no fix for this issue as of now.

If it solves your problem, you may try to use has filter on every level in your query.
But note that doing so is not the same as @cascade. For example, consider these 2 DQL queries:

Query-1

query {
  queryPerson(func: type(Person)) @cascade(fields: ["name","friends"]) {
    name
    friends {
      name
    }
  }
}

Query-2

query {
  queryPerson(func: type(Person)) @filter(has(name) AND has(friends)) {
    name
    friends @filter(has(name) AND has(friends)) {
      name
    }
  }
}

Given this DQL schema:

type Person {
  name
  friends
}
name: string .
friends: [uid] .

And the following data-set:

_:a <name> "Alice" .
_:b <name> "Bob" .
_:c <name> "Charlie" .

_:a <friend> _:b .
_:b <friend> _:c .

Then the result of the two queries will be like this:

Query-1 response

{
  "queryPerson": [
    {
      "name": "Alice",
      "friends": [
        {
          "name": "Bob"
        }
      ]
    }
  ]
}

Query-2 response

{
  "queryPerson": [
    {
      "name": "Alice",
      "friends": [
        {
          "name": "Bob"
        }
      ]
    },
    {
      "name": "Bob",
      "friends": []
    }
  ]
}

Note that the 2nd query will work correctly with pagination, but it will not remove those parents for which a deep descendent was missing some data.

1 Like