How to use variables for pagination?

Hi All,

I am trying to page query results, following the documentation example I have come up with the following query.

query test($a: int = 2, $name: string = "Steven") {
  ID as var(func: allofterms(name@en, $name)) @filter(has(director.film)) {
    director.film {
      stars as count(starring)
    }
    totalActors as sum(val(stars))
  }

  mostStars(func: uid(ID), orderdesc: val(totalActors), first: $a) {
    name@en
    stars : val(totalActors)

    director.film {
      name@en
    }
  }
}

Running this query gives me:

Expecting a comma. Got: lex.Item [9] "a"

However, replacing first: $a, with first: 2 works as expected. Am missing something here?

Hey @monish

I think this is a bug related to QueryWithVars using `after:` fails · Issue #2099 · dgraph-io/dgraph · GitHub. It should be easy to fix though. I am going to work on a fix now and should have something for you soon.

I have merged a fix to master with Support GraphQL vars in first, offset and after at root. · dgraph-io/dgraph@e05f0fd · GitHub and it would be part of the nightly release.

Thanks for the quick fix!