# Graphql Cost Algorithm

**URL:** <https://community.shopify.dev/t/graphql-cost-algorithm/4996>\
**Category:** GraphQL Admin API Troubleshooting\
**Tags:** rest-migration\
**Created:** [December 26, 2024, 3:38pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996 "2024-12-26T15:38:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Merchbees](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Merchbees](https://community.shopify.dev/u/Merchbees)\
**Post date:** [December 26, 2024, 3:38pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/1 "2024-12-26T15:38:55Z")

</div>

Can anyone explain how the new GraphQL cost computation algorithm works? Any formulas for nested fields would be appreciated.

---

<div class="post-metadata">

**Author:** ![remy727](https://sea1.discourse-cdn.com/shopifycommunity/user_avatar/community.shopify.dev/remy727/32/22340_2.png) [@remy727](https://community.shopify.dev/u/remy727)\
**Post date:** [December 26, 2024, 4:03pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/2 "2024-12-26T16:03:04Z")

</div>

Does this help you?

- [Rate Limiting GraphQL APIs by Calculating Query Complexity](https://shopify.engineering/rate-limiting-graphql-apis-calculating-query-complexity)
- [Shopify API rate limits](https://shopify.dev/docs/api/usage/rate-limits)

---

<div class="post-metadata">

**Author:** ![Merchbees](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Merchbees](https://community.shopify.dev/u/Merchbees)\
**Post date:** [December 26, 2024, 4:41pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/3 "2024-12-26T16:41:19Z")

</div>

Hey @remy727, this blog post is from 2021. I believe that due to the migration from REST to GraphQL, they changed the logic. Now, retrieving 100 items doesn’t cost you 100 points.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea1.discourse-cdn.com/shopifycommunity/user_avatar/community.shopify.dev/daniel/32/2321_2.png) [@daniel](https://community.shopify.dev/u/daniel)\
**Post date:** [December 26, 2024, 4:52pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/4 "2024-12-26T16:52:51Z")

</div>

> [@Merchbees](#):
>
> this blog post is from 2021

the second link is from the current doc, you have all the details there:

> **[Shopify API rate limits](https://shopify.dev/docs/api/usage/rate-limits#cost-calculation)**
>
> Learn about Shopify API rate limits and how we control access to the platform. Get tips on how to keep your apps within the limit.

---

<div class="post-metadata">

**Author:** ![Merchbees](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Merchbees](https://community.shopify.dev/u/Merchbees)\
**Post date:** [December 26, 2024, 6:20pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/5 "2024-12-26T18:20:56Z")

</div>

Hey @daniel @remy727

Based on the documentation, can you explain why the queries below have the corresponding costs?

Cost: 12

> query {  
> products(first:240) {  
> edges {  
> node {  
> title  
> }  
> }  
> }  
> }

Cost: 6

> query {  
> products(first:12) {  
> edges {  
> node {  
> title  
> }  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![remy727](https://sea1.discourse-cdn.com/shopifycommunity/user_avatar/community.shopify.dev/remy727/32/22340_2.png) [@remy727](https://community.shopify.dev/u/remy727)\
**Post date:** [December 26, 2024, 7:57pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/6 "2024-12-26T19:57:48Z")

</div>

The cost should be different based on how many products are being returned.

---

<div class="post-metadata">

**Author:** ![Merchbees](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Merchbees](https://community.shopify.dev/u/Merchbees)\
**Post date:** [December 26, 2024, 8:22pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/7 "2024-12-26T20:22:37Z")

</div>

That’s not relevant @remy727 I’m talking about the requested cost.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea1.discourse-cdn.com/shopifycommunity/user_avatar/community.shopify.dev/daniel/32/2321_2.png) [@daniel](https://community.shopify.dev/u/daniel)\
**Post date:** [December 26, 2024, 10:42pm UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/8 "2024-12-26T22:42:23Z")

</div>

You can include the header `Shopify-GraphQL-Cost-Debug=1` in your request to get a detailed breakdown of how each field contributes to the requested cost

---

<div class="post-metadata">

**Author:** ![Merchbees](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Merchbees](https://community.shopify.dev/u/Merchbees)\
**Post date:** [December 27, 2024, 6:28am UTC](https://community.shopify.dev/t/graphql-cost-algorithm/4996/9 "2024-12-27T06:28:23Z")

</div>

Guys please don’t spam the topic if you don’t know the answer.
