Wp-graphql-woocommerce: Need help about use the Cursor when query products

Created on 1 Jun 2021  路  4Comments  路  Source: wp-graphql/wp-graphql-woocommerce

Hi, I am so confuse with Cursor to make a pagination...
I have a query products like this

query GET_PRODUCTS($first: Int, $before: String, $after: String, $last: Int) {
  products(first: $first, before: $before, after: $after, last: $last) {
    nodes {
      name
      slug
      databaseId

    }
    pageInfo {
      endCursor
      hasNextPage
      hasPreviousPage
      startCursor
    }
  }
}

I will have list of products and pageInfo like this

"pageInfo": {
        "endCursor": "YXJyYXljb25uZWN0aW9uOjIyMjA=",
        "hasNextPage": true,
        "hasPreviousPage": false,
        "startCursor": "YXJyYXljb25uZWN0aW9uOjIyMzg="
      }

Then if I want get list of next 10 products I will use input like this?

{
"first": 10  ,
 "after":  endCursorStringAbove
}

I tried but I will return me

"pageInfo": {
        "endCursor": null,
        "hasNextPage": true,
        "hasPreviousPage": true,
        "startCursor": null
      }

I don't understand how this work :(

Most helpful comment

@IRediTOTO @scottyzen Due to a recent change in WPGraphQL there is a bug in pagination that will be resolve in the next release v0.10.0.

This issue is a duplicate of #474

All 4 comments

:| Oki I got how it work
The first input need increase too. Why do you make this so confuse. Why dont use skip ?

I'm having the same issue. I got it to work using the same way you mentioned (by increasing the first input). Feels very hacky. When querying posts you don't have to worry about updating the first input.

@IRediTOTO @scottyzen Due to a recent change in WPGraphQL there is a bug in pagination that will be resolve in the next release v0.10.0.

This issue is a duplicate of #474

Is there any other way to paginate that could be used for now until the cursor pagination is fixed? Not sure...maybe the traditional one with the numbers of pages, like google?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohaimenmahi picture mohaimenmahi  路  5Comments

mehidi258 picture mehidi258  路  3Comments

stefanos82 picture stefanos82  路  7Comments

aresrioja10 picture aresrioja10  路  6Comments

huniqcast picture huniqcast  路  3Comments