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?
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024