# Graphql on hand inventory query complexity

**URL:** <https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559>\
**Category:** GraphQL API\
**Created:** [September 16, 2021, 5:13pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559 "2021-09-16T17:13:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@joe](https://community.shiphero.com/u/joe)\
**Post date:** [September 16, 2021, 5:13pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/1 "2021-09-16T17:13:16Z")

</div>

If I look for on hand inventory for a product, I can use a query like this, and the complexity is only 1.

```auto
query{
  product(sku: "x"){
    request_id
    complexity
    data {
      warehouse_products{
        sku 
          warehouse_id
          price
          value
          on_hand
				
      }
    }
  }
}

```

If I add the available field, it increases complexity to 31, making it much slower to get current available inventory for a group of products. Is there some reason for this complexity increase with available inventory?

---

<div class="post-metadata">

**Author:** ![Theresa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/theresa/32/377_2.png) [@Theresa](https://community.shiphero.com/u/Theresa)\
**Post date:** [September 16, 2021, 6:08pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/2 "2021-09-16T18:08:53Z")

</div>

Hi @joe, welcome!  
That is a great question! The reason that the complexity of the available number is so much higher than the on-hand number is the amount of calculation and data points that are accessed in that calculation. For instance, the on-hand is pulling one value. The available has to touch on several values and calculate results based on the computation of values for a result. (to check if it’s virtual or if it is a kit, the kit component on-hand, the allocation, etc. )

---

<div class="post-metadata">

**Author:** ![jeremyw](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jeremyw](https://community.shiphero.com/u/jeremyw)\
**Post date:** [September 17, 2021, 10:26am UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/3 "2021-09-17T10:26:47Z")

</div>

Hi @joe,

I ran into this, too. I understand that it’s a calculated field and more computationally intense, but an extra 30 to the complexity per SKU seems _really_ high in my opinion. (But I’m not a GraphQL server programmer, so what do I know?)

It’s not a pretty solution, but I wind up using the API for what I can, but then I’ll go to the Products page and manually export a CSV of everything just to get the available field and merge them with a script. It’s annoying because it’s manual, but only takes seconds instead of the hours it would take to get the same data via the API.

---

<div class="post-metadata">

**Author:** ![joe](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@joe](https://community.shiphero.com/u/joe)\
**Post date:** [September 17, 2021, 4:20pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/4 "2021-09-17T16:20:09Z")

</div>

Thanks for the explanation.

---

<div class="post-metadata">

**Author:** ![joe](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@joe](https://community.shiphero.com/u/joe)\
**Post date:** [September 17, 2021, 4:32pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/5 "2021-09-17T16:32:39Z")

</div>

In my case I only have api access but it is disappointing when an api is more limiting than a report available to the end user.

---

<div class="post-metadata">

**Author:** ![jeremyw](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jeremyw](https://community.shiphero.com/u/jeremyw)\
**Post date:** [September 17, 2021, 4:46pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/6 "2021-09-17T16:46:06Z")

</div>

It never occurred to me that one might have access only to the API. Yeah, that’s rough. ☹

---

<div class="post-metadata">

**Author:** ![Theresa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/theresa/32/377_2.png) [@Theresa](https://community.shiphero.com/u/Theresa)\
**Post date:** [October 1, 2021, 12:00pm UTC](https://community.shiphero.com/t/graphql-on-hand-inventory-query-complexity/1559/7 "2021-10-01T12:00:10Z")

</div>

This topic was automatically closed after 14 days. New replies are no longer allowed.
