How to use @cascade in GraphQL

Reading the changelog:

Introduce @cascade in GraphQL. Fixes #4789. (#5179)

Which should reference #5511 (cascade) instead of #5179 (auth)

I understand this is on the bleeding edge and still only available on the master branch. And I understand there is no docs for it at this time. I am just wondering how it might work?

Given example:

type Person {
  id: ID!
  name: String @search(by: [hash, regexp, fulltext])
  hasGiven: [Donations] @hasInverse(field: from)
  hasReceived: [Donations] @hasInverse(field: to)
}

type Donations {
  id: ID!
  amount: Float! @search
  from: Person @hasInverse(field: hasGiven)
  to: Person @hasInverse(field: hasReceived)
}

If I want to be able to use cascade to find only people who have given or find people who have only received, I understand that I would put @cascade on:
hasGiven: [Donations] @hasInverse(field: from) @cascade
hasReceived: [Donations] @hasInverse(field: to) @cascade

But, after submitting the new schema (using :master image in docker) I am not seeing any difference in the schema giving me the cascade or filter options. The schema is accepted as valid though.

Is there a trick to using this somehow?

Oh, I think I figured it out!

you simply use the @cascade as a directive while writing the GraphQL query itself:

{
  queryPerson @cascade {
    name
    hasGiven {
      amount
      to {
        name
      }
    }
  }
}
1 Like

Yes, that’s right. You should just use the directive at any level in the query that you want to apply it at. You don’t have to specify it in the schema.

I made a pull request to update the docs: docs(GraphQL): Added docs for query directives by amaster507 · Pull Request #15 · dgraph-io/graphql-dgraph-web · GitHub