I am trying to consume Shopify GraphQL API for Admin in PHP ( Laravel ).
Rate limiting and throttling works differently in GraphQL api as compared to REST api, its calculated based on the cost of the query.
Few points to keep in mind:
- Maximum available cost is 1000 for one api call (query).
- If you have consumed some points from 1000, every second, 50 points will be restored.
- If you have less points of cost in your bucket, and you make a query of cost higher than that, it will throttle.
The query that I am passing to api has an estimated cost of 502, represented by requestedQueryCost. Whereas, actualQueryCost represents the actual response returned by the api for a specific shop.
In above snapshot, its the worst case scenario, requestedQueryCost is equal to acutalQueryCost for a store with heavy number of orders.
Now, when this query is executed I have consumed 502 points, 498 left, 1 second elapsed, 50 points added = 548 , and I can make a second api call to fetch second page of data. After second api call I will have less points left, so I will have to put sleep for 1 or 2 seconds to gain the points to make api call.
In the case shown in snapshot, i had to put 10 seconds sleep wait in order to restore 500 points to make next api call.
Problem: How to best decide sleep (wait) time for different shops? We don't want all shops to wait for 10 seconds even if they have less query cost.
Note: For code reference, see my answer below.
bulkOperations
, you can execute 1 per shop async and no pagination or limits apply. – Daniel W.