I am using the node.js module "shopify-api-node" to call Shopifys graphql API. I can see in the documentation you can access the throttling information via callGraphqlLimits, but how are you supposed to use it to throttle the requests?
If I e.g. want to delay the next call 5s I tried this, but the delay seems to be executed asynchronously (while testing I force immediate throttling by checking when limit is less than 1000):
shopify.on('callGraphqlLimits', async (limits) => {
console.log(limits)
if (limits.remaining < 1000){
console.log('Delaying 5s')
await delay(5000)
}
})
Thanks, -Louise
Here is how I manage throttling using that library. Conceptually the process is as follows;
So if I had an expensive query, the process could look like this (pagination stuff omitted for brevity)
This will always clear out your current cost, so you will always have a "full bucket". However, if we knew the cost for the query you could do something more sophisticated. Ideally, you don't want to wait until your bucket is full, but just wait long enough so you have enough cost available to perform your query.