A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello!
For some reason shopify admin graphql returns draft items even if I've added condition in query to return only active products.
{
productVariants(first:12, query: "product_status:active") {
edges {
node {
id
title
availableForSale
product {
id
status
title
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Hey @sanjar
Thanks for taking the time to post in the API board. The ProductStatus is actually an enum rather than a string, which is probably what's throwing off the results in your query.
Can you try the same query with all capitals, like this:
query: "product_status:ACTIVE"
JamesG | API Support @ 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
Hello @JamesG
Thank you for your reply. Unfortunately that not helped.
When I query ACTIVE, its not returning me anything.
During my several test i've noticed that uppercase "ACTIVE" or "DRAFT" doesnt work at all. However, "active" or "draft" works, and strange thing is that "active" sometimes returns even draft products, and after several tries (requests) it returns only Active products. I feel like it is some kind of delay in backend.
How to replicate:
1. Copy paste graphql from post.
2. Make gql request, you will see active products.
3. Make draft first product returned
4. go back to gql app to make request again.
5. you will see status: DRAFT
6. wait a bit and try to make requests again, and after 2-3 requests you will only see active products.
Thanks.
Hey @sanjar
Thanks for sharing those steps. I was able to replicate the same delay you described when looking up the product's status via the the ProductVariantConnection using one of my test stores.
I suspect that the ProductVariantConnection could be seeing a delay while waiting for the product info to be re-indexed, and but will flag this with our developers for them to take a closer look.
After a bit of testing, I also found that querying the ProductConnection for the product's status was more reliable so I would recommend either implementing a delay before querying with productVariants immediately after updating products, or reformatting your queries to use products on the query root for now:
{
products(first: 10, query: "status:active") {
edges {
cursor
node {
id
status
title
variants(first:10){
edges{
node{
id
title
availableForSale
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Cheers
JamesG | API Support @ 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