Skip to content

Record is skipped when using pagination #956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BrianSiimAndersenEG opened this issue Apr 21, 2024 · 3 comments
Closed

Record is skipped when using pagination #956

BrianSiimAndersenEG opened this issue Apr 21, 2024 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@BrianSiimAndersenEG
Copy link

I'm experiencing an issue with the new way to do pagination.

I've created a GraphQL query:

countries(first: Int, after: String, last: Int, before: String): CountryConnection

And a corresponding controller method, that takes a ScrollSubrange argument).

@QueryMapping
public Window<Country> countries(ScrollSubrange subrange) {
    ScrollPosition position = subrange.position().orElse(ScrollPosition.offset());
    Limit limit = Limit.of(subrange.count().orElse(100));
    Sort sort = Sort.by("name").ascending();
    return countryRepository.findAllBy(position, limit, sort);
}

I'm calling a repository method, that only takes the position, limit and sort:

Window<Country> findAllBy(ScrollPosition position, Limit limit, Sort sort);

When I perform this query:

query Countries {
    countries(first: 3) {
        edges {
            cursor
            node {
                name
            }
        }
    }
}

I will receive the first three countries with cursors T18x, T18y and T18z:

{
    "data": {
        "countries": {
            "edges": [
                {
                    "cursor": "T18x",
                    "node": {
                        "name": "Afghanistan"
                    }
                },
                {
                    "cursor": "T18y",
                    "node": {
                        "name": "Albania"
                    }
                },
                {
                    "cursor": "T18z",
                    "node": {
                        "name": "Algeria"
                    }
                }
            ]
        }
    }
}

However, when I perform the query a second time, and specifying that I want the first two countries starting after cursor T18y:

query Countries {
    countries(first: 2, after: "T18y") {
        edges {
            cursor
            node {
                name
            }
        }
    }
}

it will skip a record with cursor T18z:

{
    "data": {
        "countries": {
            "edges": [
                {
                    "cursor": "T180",
                    "node": {
                        "name": "Andorra"
                    }
                },
                {
                    "cursor": "T181",
                    "node": {
                        "name": "Angola"
                    }
                }
            ]
        }
    }
}

It should have return T18z and T180 instead of T180 and T181.

Is this a bug in Spring for GraphQL, or am I doing something wrong?

It seems to me that when the cursors are returned they start with index 1 (T18x), but when passing them back to the service in the "after" parameter, it expects the indexes to start with 0. And thereby a record is missed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 21, 2024
@bclozel
Copy link
Member

bclozel commented Apr 21, 2024

Are you using 1.2.6? See #925 for a possible duplicate.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Apr 21, 2024
@BrianSiimAndersenEG
Copy link
Author

BrianSiimAndersenEG commented Apr 21, 2024

I'm using 1.2.5 (Spring Boot 3.2.4). I can see that a Spring 3.2.5 with 1.2.6 got released the other day. I just gave it a try, and it works like a charm.

@bclozel
Copy link
Member

bclozel commented Apr 21, 2024

Thanks for letting us know! I'm glad things work for you now.

@bclozel bclozel added status: duplicate A duplicate of another issue and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Apr 21, 2024
@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants