Storefront API pagination returns error when sorting by CREATED

For the last few days, when sending a query for the next page of products in a collection, the API returns an error if I am also sorting with the CREATED option. For instance:

query MyQuery {
  collection(handle: "outdoors") {
    handle
    id
    products(
      first: 5
      filters: {productType: "Vinyl Decal"}
      reverse: true
      sortKey: CREATED
    ) {
      pageInfo {
        endCursor
        hasNextPage
        hasPreviousPage
        startCursor
      }
      edges {
        node {
          id
          handle
        }
      }
    }
  }
}

The above query will return the expected results, but when I send a request for the next N products after the end cursor, an error is returned:

query MyQuery {
  collection(handle: "outdoors") {
    handle
    id
    products(
      first: 5
      filters: {productType: "Vinyl Decal"}
      reverse: true
      sortKey: CREATED
      after: "eyJsYXN0X3ZhbHVlIjoiNCIsImxhc3RfaWQiOjk1NjE2ODUxMzE1NDh9"
    ) {
      pageInfo {
        endCursor
        hasNextPage
        hasPreviousPage
        startCursor
      }
      edges {
        node {
          id
          handle
        }
      }
    }
  }
}

returns:

{
  "data": {
    "collection": null
  },
  "errors": [
    {
      "message": "Invalid cursor for current pagination sort.",
      "locations": [
        {
          "line": 5,
          "column": 5
        }
      ],
      "path": [
        "collection",
        "products"
      ]
    }
  ]
}

This behavior began recently and nothing on my end had changed to cause it. Ideally I wouldn’t need to hack around this because the normal behavior is much more stable and predictable when it works. I’m wondering if anyone has experienced / solved this issue

3 Likes