Hello, Everyone!
I have a question regarding the calculation of query costs in the Shopify Admin GraphQL API. According to the documentation and the article, the cost of a query should be proportional to the number of objects and connections requested. However, I am seeing a significant discrepancy between my manual calculation and the actual cost returned by the API.
For example, I ran the following query:
query getVariantsInventoryItem($id: ID!) {
product(id: $id) {
variants(first: 250) {
nodes {
inventoryItem {
id
tracked
}
}
}
}
}
Based on the article Rate Limiting GraphQL APIs by Calculating Query Complexity - Shopify , I expected this query to cost 503 points, assuming each variant and inventory item would be counted individually. However, the API response provided:
with the following breakdown in the extensions.cost.fields object:
{
"data": {
"product": null
},
"extensions": {
"cost": {
"requestedQueryCost": 25,
"actualQueryCost": 1,
"throttleStatus": {
"maximumAvailable": 2000,
"currentlyAvailable": 1999,
"restoreRate": 100
},
"fields": [
{
"path": [
"product",
"variants",
"nodes",
"inventoryItem",
"id"
],
"definedCost": 0,
"requestedTotalCost": 0,
"requestedChildrenCost": null
},
{
"path": [
"product",
"variants",
"nodes",
"inventoryItem",
"tracked"
],
"definedCost": 0,
"requestedTotalCost": 0,
"requestedChildrenCost": null
},
{
"path": [
"product",
"variants",
"nodes",
"inventoryItem"
],
"definedCost": 1,
"requestedTotalCost": 1,
"requestedChildrenCost": 0
},
{
"path": [
"product",
"variants",
"nodes"
],
"definedCost": 1,
"requestedTotalCost": 2,
"requestedChildrenCost": 1
},
{
"path": [
"product",
"variants"
],
"definedCost": null,
"requestedTotalCost": 24,
"requestedChildrenCost": 2
},
{
"path": [
"product"
],
"definedCost": 1,
"requestedTotalCost": 25,
"requestedChildrenCost": 24
}
]
}
}
}
Could you please clarify why the query cost is so much lower than expected? Is there a change in how costs are calculated, or is there an internal optimization that affects the returned values? Any insights would be greatly appreciated.
Thank you for your time!