async-graphql / examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Starwars connection result is wrong

hffmnn opened this issue · comments

When running the StarWars example I looked into the pageInfo for humans (There is a total count of 5 humans. ).

Requesting the first 3 gives this (which is correct):

...
"pageInfo": {
        "startCursor": "0",
        "endCursor": "2",
        "hasNextPage": true,
        "hasPreviousPage": false
      }
...

Requesting the next 3 after the first 3 (first:3, after: "2") gives this (which is wrong, hasNextPage should be false)

"pageInfo": {
        "startCursor": "3",
        "endCursor": "4",
        "hasNextPage": true,
        "hasPreviousPage": true
      }

I played around with it a little bit further and found other things:

humans(first: 0, after: "2") gives

"pageInfo": {
        "startCursor": null,
        "endCursor": null,
        "hasNextPage": false, // should be true
        "hasPreviousPage": true
      }

Because the calculation to get the connection data is rather complex and mutativ (if this is a word) I didn't really understand what was going wrong.

🤔 I also wondered if these calculations could get abstracted away somehow (given the total count of items and all the other cursor info as input)