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)
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'