Pagination using "after" seems to ignore sorting

Hi, I’m running the following query

{
  me(func: uid(0x54812)) {
    uid
    name@en
    director.film (orderdesc: name@en) (first:6)  {
      uid
      name@en
    }
  }
}

then, using the uid of the last item returned, running this query

{
  me(func: uid(0x54812)) {
    uid
    name@en
    director.film (orderdesc: name@en) (first:6, after: 0x80d60)  {
      uid
      name@en
    }
  }
}

I would expect this 2nd query to return identical results to this query:

{
  me(func: uid(0x54812)) {
    uid
    name@en
    director.film (orderdesc: name@en) (first:6, offset: 6)  {
      uid
      name@en
    }
  }
}

however, it returns a mix of results including a few from the first query.

As stated in the title, it seems to me that the “after” operation is being performed before the sorting occurs, which is not what I would expect. To further support this, I notice that removing the “orderdesc” from the query will produce results as expected, and both the “offset” and “after” versions of the query will return identical results.

Is this a bug or intended behavior? If not a bug, can anyone help me get this working?

I’ve tried several variations of this, with the sorting/pagination at the root query, using variables, and a few others, but all seem to have the same behavior and I haven’t been able to get it working how I would like.

To anyone looking for a workaround for this, here is what I did:

{
  var (func: uid(0x80d60)) {
    aftername as name@en
  }
 
  me(func: uid(0x54812)) {
    uid
    name@en
    director.film (orderdesc: name@en) (first:6) @filter(lt(name@en, val(aftername)))  {
      uid
      name@en
    }
  }
}
1 Like