Skip to content

Pagination with "after" cursor results in ScrollPosition that skips one extra item #925

Closed
@tata-dr-dk

Description

@tata-dr-dk

Using Graphql Query 'after' option with a cursor of position N, yields a result-set starting from position N+2 upwards, skipping the document right after the cursor that should have been included (N+1).

Using the latest graphql and mongodb starters

	implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
	implementation 'org.springframework.boot:spring-boot-starter-graphql'

Using graphql @QueryMapping annotation and ScrollSubrange on a controller

    @QueryMapping
    public Window<Customer> customers(@Argument String storeNumber, ScrollSubrange subrange) {
       //...
    }

and a query:

query MyQuery {
  customers(storeNumber: "123", after: "T18x") {
    edges {
      cursor
      node {
        name
        storeNumber
      }
    }
  }
}

where 'T18x' is the cursor of the first document, results in subrange.position() of 2.

Using that position in a mongodb Query:

        var query = Query.query(criteria)
                .with(scrollPosition);

would actually skip 2 documents, and not start from document of position 2 (thus not inclusive).
Seems to be related to #916

A project reproducing the bug can be found here: graphql-bug

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions