Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

GraphQL productVariant query: "product_status:active" issue

GraphQL productVariant query: "product_status:active" issue

sanjar
Shopify Partner
21 1 2

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
    }
  }
}

 

 

Screen Shot 2022-06-23 at 9.43.42 AM.png

Replies 3 (3)

JamesG
Shopify Staff
42 10 11

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

sanjar
Shopify Partner
21 1 2

Hello @JamesG 

Thank you for your reply. Unfortunately that not helped. 

When I query ACTIVE, its not returning me anything. 

 

Screen Shot 2022-08-08 at 1.08.04 PM.png

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.

JamesG
Shopify Staff
42 10 11

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