How to get inventory levels (quantity available) by providing many skus in GraphQL variables

Topic summary

A user needed to query Shopify’s GraphQL API for inventory levels across multiple SKUs using variables, rather than hardcoding a single SKU.

The Challenge:

  • The original query worked with one SKU (sku:123) but needed to scale to multiple SKUs
  • The user wanted to avoid using OR operators directly in the query string
  • Initial assumption that SKUs could be passed as an array variable proved incorrect

The Solution:

  • Shopify’s GraphQL API doesn’t accept SKU arrays directly in variables
  • Instead, format the SKU query string client-side before sending: skus.map(sku => \sku:‘${sku}’`).join(" OR ")`
  • Pass the formatted string (e.g., "sku:'123' OR sku:'124' OR sku:'125'") as a single $skuQuery variable
  • Update the query to accept $skuQuery: String! parameter

Resolution:
The user confirmed this approach solved their problem, acknowledging they had incorrectly assumed SKUs could be handled like ID arrays in Shopify’s API.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

I’m not experienced with GraphQL and want to get inventory levels from Shopify by providing many SKUs through variables. Maybe this will help by providing a working solution that I want to change to using variables. How can I convert the following from using 1 sku to query many skus on the query using variables? (I realize variables below are doing nothing, just indicating I want to use multiple SKU numbers and not use OR in the query)

{
inventoryItems(first: 3, query: “sku:123”) {
edges {
node {
id
sku
inventoryLevels(first: 3) {
edges {
node {
id
quantities(names: “available”) {
name
quantity
}
}
}
}
}
}
}
}

VARIABLES:
{
“skus”: [
“123”,
“124”,
“125”,
“126”
]
}

Hey @QGoin ,

The trick is that Shopify’s GraphQL requires special formatting for SKU queries. You’ll need to prepare your query string on the client side before sending it.

Here’s the approach:

// Prepare your SKUs array
const skus = ["123", "124", "125", "126"];

// Format them for Shopify's query syntax
const skuQuery = skus.map(sku => `sku:'${sku}'`).join(" OR ");

// This gives you: sku:'123' OR sku:'124' OR sku:'125' OR sku:'126'

Then your GraphQL query would look like:

query GetInventoryLevels($skuQuery: String!) {
  inventoryItems(first: 250, query: $skuQuery) {
    edges {
      node {
        id
        sku
        inventoryLevels(first: 3) {
          edges {
            node {
              id
              quantities(names: "available") {
                name
                quantity
              }
            }
          }
        }
      }
    }
  }
}

With variables:

{
  "skuQuery": "sku:'123' OR sku:'124' OR sku:'125' OR sku:'126'"
}

The key insight is that Shopify’s API doesn’t directly support arrays for SKU queries, but it does support OR conditions in the query string.

Let me know if you run into any issues with this approach!

Best,

Shubham | Untechnickle

Thanks, Shubham! That answers the piece I was missing. I saw ID could have be an array so I made a wrong assumption.

Appreciate the help!