where we get a cursor from the last item and use that to paginate

Highlighted
Tourist
8 0 1

where we get a cursor from the last item in qraphql and use that to paginate.

0 Likes
Highlighted
Shopify Partner
1777 211 370

This is an example of a request:

query {
  shop {
    name
    products(first: 5) {
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      edges {
        node {
          id
          handle
        }
        cursor
      }
    }
  }
}

Notice the cursor field under edges node. This instructs the backend to return you the cursor with each product in the result set. You just have to get that value from the last item you have received and pass with the next request like so:

query {
  shop {
    name
    products(first: 5 after:"<cursor_value_of_last_product>") {
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      edges {
        node {
          id
          handle
        }
        cursor
      }
    }
  }
}

 Cursor value to go instead of the placeholder <cursor_value_of_last_product>

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Tourist
8 0 1

Can you add "endCursor" in pageInfo parameter. It is missing in pageInfo. I have checked in graphql documentation

 

Example:

      pageInfo {
        endCursor
        hasNextPage
        hasPreviousPage

      }

 

0 Likes