A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello guys,
I am running the following query to get the product's data, but when I add the field to get inventory levels and location, it returns the error "Bulk queries cannot contain more than 5 connections".
Using Grapql API version 2023-10.
1. How can I get the whole data of products with the bulk query?
2. Also, how to get the inventory and its location for products? I am getting it only at the variants level. Is there any possibility of getting this at the product level?
mutation { bulkOperationRunQuery( query: """ { products { edges { node { id createdAt updatedAt title handle descriptionHtml productType collections { edges { node { id title } } } metafields { edges { node { namespace key value } } } variants { edges { node { id title weight weightUnit price inventoryQuantity metafields { edges { node { namespace key value } } } } } } options { name position values } priceRange { minVariantPrice { amount currencyCode } maxVariantPrice { amount currencyCode } } } } } } """ ) { bulkOperation { id status } userErrors { field message } } } `
Hi Ravi,
The error you're encountering ("Bulk queries cannot contain more than 5 connections") is due to a limitation in Shopify's GraphQL API. Each "connection" (like variants, metafields, or collections) counts towards this limit. To resolve this, you can split your query into multiple bulk operations. For example, run one bulk operation for basic product data and another for variants and associated metafields.
Regarding the inventory and location data at the product level, Shopify's data model associates inventory information with product variants, not directly with products. Each variant of a product can have different inventory levels and locations. Therefore, you need to access inventory data through the variants.
However, if you want to aggregate this data at the product level, you would need to do so programmatically after fetching the data. You can fetch inventory levels and locations for each variant and then aggregate this information in your application logic to reflect it at the product level.
Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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
Thanks Liam,
But here we have a limitation GRAPHQL bulk operation is it can run once at a time, so do we need to wait until the first bulk operation is completed? then again make the call for fetch
variants, metafields, collections. Also, we have to fetch the meta fields of variants and collections as good collections. Is there any example query for multiple bulk operations?
Also, for inventory with a location at the variant level, how can we fetch what is the query I tried the following query under products > Variants but did not get anything returned blank. If you have any latest thing then please help me on this.
inventoryItem {
id
inventoryLevels(first: 6) {
edges {
node {
id
available
location {
id
name
address {
city
}
}
}
}
}
Also, can we handle the products if we have 100000 with bulk operation?
mutation {
bulkOperationRunQuery(
query: """
{
products {
edges {
node {
id
createdAt
updatedAt
title
handle
descriptionHtml
productType
variants {
edges {
node {
id
title
weight
sku
weightUnit
price
inventoryQuantity
inventoryItem {
id
inventoryLevels(first: 6) {
edges {
node {
id
available
location {
id
name
address {
city
}
}
}
}
}
}
metafields {
edges {
node {
id
namespace
key
value
}
}
}
}
}
}
options {
name
position
values
}
priceRange {
minVariantPrice {
amount
currencyCode
}
maxVariantPrice {
amount
currencyCode
}
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
Hey @RaviGohil2211 and @Liam Hope you both are doing well!
I want to ask about the bulk query for getting whole product data like variants, price, options Etc.. but when i run the following code or the code provided by @RaviGohil2211 it didn't give me variants in the response.
This is the code i am using for getting product details. I also run the query provided by @RaviGohil2211 but facing same issue.
I am using remix.js for my shopify app
API_VERSION: 2024-03
const response = await admin.graphql(
`#graphql
mutation {bulkOperationRunQuery(
query: """{
products {
edges {
node {
id
title
descriptionHtml
vendor
status
productType
totalInventory
tags
variants(first: 250) {
edges {
node {
id
selectedOptions {
name
value
}
price
# Add other desired variant fields here (e.g., inventory)
}
}
}
category{
id
name
fullName
}
options(first: 250) {
id
name
values
position
optionValues{
id
name
}
}
featuredImage {
id
url
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}`)
Thanks Liam
When querying products with many of the connections you quite easily get up to 5 if you also need metafields. I understand you want to prohibit people from querying all the resolvers, but I think it could be a great help if you could increase the threshold just a little bit maybe 8. Alternatively you could make an metafields connections endpoint like https://shopify.dev/docs/api/admin-graphql/unstable/queries/metafields , where you could query without specifying an owner, but only get the id's of the connected fields.