MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
946 stars 278 forks source link

GraphQL pagination strategy #490

Closed pociej closed 2 years ago

pociej commented 3 years ago

As we know shopify rate limits graphQL call by size of the query. This leads to serious problems when you want to get 'all' of paginated resources. Let's say all the collections, or product will all the variants. It is quite often case that one needs 'all' but 'thank' graphQL pagination there is no way. What you can do is to specify N number of element per page and it works ( i mean shopify do not reject query) continue with this N page by page, based on pageInfo from api response. However this N can be different per query.  Look at example, lets write query that takes product with all collections that product belongs to 


product(id: ${id}) {
      availablePublicationCount
      collections(first: 5) {
        edges {
          node {
            handle
          }
        }
      }

As we can see, here is (firstL5) in context of collections. Let's say i want to get all the collections ( show me use case when one wants to take first 5 collection only like above ? ). Is 5 proper number ? safest is 1 but for sure it can potentially end up with thousands of API calls. So what is proper strategy? Guess the number, if doesn't work then try another one , a bit smaller? 

That doesn't sounds like nice approach, especially taking into account there can be multiple paginations per query. For example we could be interested not only in collection but also also images of product. Anyways, as there is not option to say collection (first : all) I don't see better way than described above.

Of course it is better to calculate query weight locally. Do you think that exposing query weight calculator from this package is good idea, or it should be separated one?

ozzyonfire commented 3 years ago

Related to #489. With that problem addressed we should be able to build a pagination strategy. I haven't had a ton of time to start a pull request, but I plan on getting to this next week.