According to Shopify’s GraphQL Admin API documentation, the requested cost of a connection is based on its first or last argument.
However, the cost calculation appears to have changed recently.
For example, suppose the cost of the object is 3, and the connection itself has a fixed cost of 2. Based on the previous calculation, we would expect the requested cost to be:
Requested Cost = 2 + first × 3
However, Shopify now returns the following requested costs:
first |
requestedQueryCost |
|---|---|
| 1 | 5 |
| 2 | 5 |
| 3 | 8 |
| 4 | 8 |
| 5 | 11 |
| 6 | 11 |
| 7 | 11 |
| 8 | 14 |
| 13 | 17 |
| 21 | 20 |
| 34 | 23 |
| 55 | 26 |
| 91 | 29 |
| 149 | 32 |
| 245 | 35 |
The requested cost no longer appears to increase linearly with the first parameter. I’d like to understand how the connection cost is calculated now.
- Has Shopify changed the connection cost calculation algorithm?
- Is there any documentation describing the current algorithm?
- If the algorithm is intentionally not public, is there a recommended way to conservatively estimate the requested cost of a connection before sending the query?
Because our query is dynamic generated by the different scenarios, we need an estimation method that is reasonably close to Shopify’s requestedQueryCost and does not underestimate it. This allows us to determine an appropriate page size before sending the GraphQL request.