kirillplatonov / shopify_graphql

Less painful way to work with Shopify Graphql API in Ruby.
MIT License
59 stars 9 forks source link

Example Pagination for Graphql #25

Closed Kurbm closed 1 year ago

Kurbm commented 1 year ago

Hey @kirillplatonov,

do you have an example code how to do pagination with graphql and next and prev buttons? I have seen your pagination with looping through all items at once, but this can lead to some loading time, if a user would have lots of items.

Would be super helpful, since I‘m a bit stuck.

Best and thanks, Kurbm

kirillplatonov commented 1 year ago

This shouldn't be much different from Collection query with pagination. All you need is to check if response has next page response.data.products.pageInfo.hasNextPage and then add cursor to the next page link response.data.products.pageInfo.endCursor. Using that cursor you should be able to fetch data for the next page.