pothos icon indicating copy to clipboard operation
pothos copied to clipboard

Backward pagination with resolveOffsetConnection not working with the Relay pagination plugin

Open abathellier opened this issue 4 years ago • 2 comments

We use resolveOffsetConnection with the relay pagination plugin.

Seems that hasNextPage is not properly updated when you paginate in the opposite direction.

This query for forward pagination works:

products(first: 10, after: "T2Zmc2V0Q29ubmVjdGlvbjoxOQ==") {
    edges {
      cursor
      node {
      	id
        title
      }
    }
    pageInfo {
      endCursor
      startCursor
      hasNextPage
      hasPreviousPage
    }
    totalCount
  }

result:

"pageInfo": {
        "endCursor": "T2Zmc2V0Q29ubmVjdGlvbjoyNA==",
        "startCursor": "T2Zmc2V0Q29ubmVjdGlvbjoyMA==",
        "hasNextPage": false,
        "hasPreviousPage": true
      },
"totalCount": 25

This query for backward pagination doesn't work:

query products {
  storeProducts(last: 10, before: "T2Zmc2V0Q29ubmVjdGlvbjoyNA==") {
    edges {
      cursor
      node {
      	id
        title
      }
    }
    pageInfo {
      endCursor
      startCursor
      hasNextPage
      hasPreviousPage
    }
    totalCount
  }
}

result:

 "pageInfo": {
        "endCursor": "T2Zmc2V0Q29ubmVjdGlvbjoyMw==",
        "startCursor": "T2Zmc2V0Q29ubmVjdGlvbjoxNA==",
        "hasNextPage": false,
        "hasPreviousPage": true
      },
"totalCount": 25

hasNextPage should be true?

abathellier avatar Nov 24 '22 18:11 abathellier

jest released a fix, let me know if you are still having issues after upgrading

hayes avatar Nov 24 '22 21:11 hayes

Lighting fast fix and works great! 🙏👍

abathellier avatar Nov 25 '22 09:11 abathellier