GraphQL Paginating - Choosing page not just next or previous

Solved
Highlighted
Excursionist
22 3 0

Here is my scenario:

 

I am grabbing all the products in a collection in a loop, 20  at a time, using the cursor of the last returned product to grab the next 20. Now I have them in arrays of 20 that I send to the front end and have pages of 20. I show how many pages there are and have the common view of previous 1, 2, 3, 4.... next. The problem with this is if there are too many products I get rate limited.

 

I know that I could just grab 20 and only grab the next 20 or previous 20 when the user requests the next or previous page but then I can't show how many pages of results there are.

 

Then I thought I can grab the number of products in the collection first to show how many pages of results there are but then theres no way to click directly on one of the page numbers to jump to that page. For example say I have a collection with 400 products, I can show that there are 20 pages of results but I have no way to jump to page 10 if I wanted to.

 

Is there any way to achieve this? 

 

Thanks

0 Likes

Success.

Shopify Partner
1043 112 165

The right way to do that would be fetching the products/collections on a schedule (or do an initial import and then use webhooks to get update notifications and update your database) into your own database and feed the storefront from there instead of going directly to Shopify.

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
Excursionist
22 3 0

Of course, that makes sense! Thank you!

0 Likes