All things Shopify and commerce
Simple enough graphQL query,
{
products(first: 10) {
nodes {
id
title
category {
name
}
status
tracksInventory
totalInventory
productType
featuredMedia {
preview {
image {
url
}
}
}
}
}
}
Which works fine with GraphiQL,
But fails through a direct api access call. If I remove category, it also works fine.
The same graphQL also works fine through a server-side admin call,
const { admin } = await shopify.unauthenticated.admin(shop)
const resp = await admin
.graphql(/* GraphQL */ `
{
products(first: 10) {
nodes {
id
title
category {
name
}
status
tracksInventory
totalInventory
productType
featuredMedia {
preview {
image {
url
}
}
}
}
}
}
`)
.then((res) => res.json())
console.log(resp)
Only place it fails strangely, by category not being on a product is with direct api access,
const res = await fetch("shopify:admin/api/graphql.json", {
method: "POST",
body: JSON.stringify({
query: `{
products(first: 10) {
nodes {
id
title
category {
name
}
status
tracksInventory
totalInventory
productType
featuredMedia {
preview {
image {
url
}
}
}
}
}
}`
})
})
const response = await res.json()
console.log(response)
Solved! Go to the solution
This is an accepted solution.
Just thought about versions here, and, sure enough, category wasn't in an earlier definition of Product, https://shopify.dev/docs/api/admin-graphql/2024-01/objects/Product
So, I tried to version the graphql.json to the latest,
and? It's worked.
Seems like the documented direct access is using the old api? 2024-01 looks like?
This is an accepted solution.
Just thought about versions here, and, sure enough, category wasn't in an earlier definition of Product, https://shopify.dev/docs/api/admin-graphql/2024-01/objects/Product
So, I tried to version the graphql.json to the latest,
and? It's worked.
Seems like the documented direct access is using the old api? 2024-01 looks like?
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025