Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Has the method of calculating the requestedQueryCost changed?

Solved

Has the method of calculating the requestedQueryCost changed?

kiyotaka
Shopify Partner
4 0 3

Recently, when our app requests Shopify's GraphQL Admin API, Shopify returns a "MAX_COST_EXCEEDED" error as shown below.

The query that our app requests in the GraphQL Admin API has not changed.

Has the method of calculating the requestedQueryCost changed?

 

 

 

 

{
  "errors": [
    {
      "message": "Query cost is 1303, which exceeds the single query max cost limit (1000).\n\nSee https://shopify.dev/concepts/about-apis/rate-limits for more information on how the\ncost of a query is calculated.\n\nTo query larger amounts of data with fewer limits, bulk operations should be used instead.\nSee https://shopify.dev/api/usage/bulk-operations/queries for usage details.\n",
      "extensions": {
        "code": "MAX_COST_EXCEEDED",
        "cost": 1303,
        "maxCost": 1000,
        "documentation": "https://shopify.dev/api/usage/rate-limits?locale=ja"
      }
    }
  ]
}

 

 

 

 

 

 

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1453 238 530

This is an accepted solution.

Hi @kiyotaka - thanks for your patience on this as well. I was able to get in touch with our product team and I can confirm that we have updated the query cost calculation for the AppSubscription object. I'm unable to provide further details, but I did want to get in touch to confirm this with you. Going forward, we'd recommend using bulk operations in cases where you need to query larger sets of data in a single API Call. There's a bit more information on how this functionality works here in our developer documentation. 

 

Hope this helps!

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 530

Hey @kiyotaka, thanks for getting in touch. Could you share the query you're making (excluding any sensitive app authorization and customer/merchant information)? At the moment, we are not aware of any changes to calculation of query costs. What I have seen in the past with similar examples like this though, is that the shop-specific data has changed it can affect the payload data and result in a cost limit being exceeded.


For example, let's say that we initially set a limit on the number of variants queried under the product object in GraphQL at 50, but no shops our app has been installed on ever had more than 5 variants. Even though the number of variants hasn't reached that limit yet on the specific store, there are now extra variants that are causing the query cost to exceed the maximum allowed. 

 

Can you let us know if changing around some of the query parameters (lower limits within queries, less fields, etc.) allows the query to go through? If this doesn't appear to be the issue, please reply back here with that snippet of the query and we'd be happy take a further look. Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

kiyotaka
Shopify Partner
4 0 3

Sorry for the late reply.

The query I made is as follows.

 

query AllAppSubscriptions($num: Int!) {
  currentAppInstallation {
    allSubscriptions(first: $num) {
      pageInfo {
        hasNextPage
      }
      edges {
        cursor
        node {
          createdAt
          currentPeriodEnd
          id
          name
          returnUrl
          status
          test
          trialDays
          lineItems {
            id
            plan {
              pricingDetails {
                __typename
                ... on AppRecurringPricing {
                  interval
                  price {
                    amount
                    currencyCode
                  }
                }
                ... on AppUsagePricing {
                  balanceUsed {
                    amount
                    currencyCode
                  }
                  cappedAmount {
                    amount
                    currencyCode
                  }
                  interval
                  terms
                }
              }
            }
          }
        }
      }
    }
  }
}

I had previously requested this query with variable num as 100.

However, since early January of this year, requesting the query has been returning an error.

So now I request the query with the variable num as 10.

ShopifyDevSup
Shopify Staff
1453 238 530

This is an accepted solution.

Hi @kiyotaka - thanks for your patience on this as well. I was able to get in touch with our product team and I can confirm that we have updated the query cost calculation for the AppSubscription object. I'm unable to provide further details, but I did want to get in touch to confirm this with you. Going forward, we'd recommend using bulk operations in cases where you need to query larger sets of data in a single API Call. There's a bit more information on how this functionality works here in our developer documentation. 

 

Hope this helps!

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog