Couldn't get variant asap after it is created

Solved
Yu727
Excursionist
38 0 10

I am using this code to create a variant. It creates the variant without any issues.

 

 

mutation($input: ProductVariantInput!) {
  productVariantCreate(input: $input) {
    product {
      id
    }
    productVariant {
      id
    }
    userErrors {
      field
      message
    }
  }
}

variables = {input: {
  productId: "gid://shopify/ProductVariant/31750928957536",
  barcode: "2345678911",
  options: ["Red", "Large"],
  price: price,
  inventoryManagement: "SHOPIFY"
}}


I am using this code to get variant by barcode.

query($query: String) {
  productVariants(first: 1, query: $query) {
    edges {
      node {
        id
        product {
          id
          tags
        }
      }
    }
  }
}

variables = {query: "barcode:2345678911"}

But I can't get the variant asap using this code after running mutation to create variant.
The interesting note is that after a few minutes(1~2 minutes) I can get variant by barcode using the above code.
This code is not working only if trying to get variant asap after a new variant with the barcode is created.


Is there any reason?

 

 

Accepted Solution (1)
vix
Shopify Staff
Shopify Staff
540 103 120

This is an accepted solution.

Hi @Yu727 

 

When you run the initial mutation to create the variant, it triggers a service to index the product in your list. With that said, the variant being indexed isn't instant which is why you were seeing a delay for the variant to show up in your query. This delay is often around 30 seconds on a normal basis, depending on the number of products and other factors, this could be slightly longer like you are seeing. Are you able to reproduce a 2+ minute delay on every attempt? 

View solution in original post

Replies 5 (5)
vix
Shopify Staff
Shopify Staff
540 103 120

This is an accepted solution.

Hi @Yu727 

 

When you run the initial mutation to create the variant, it triggers a service to index the product in your list. With that said, the variant being indexed isn't instant which is why you were seeing a delay for the variant to show up in your query. This delay is often around 30 seconds on a normal basis, depending on the number of products and other factors, this could be slightly longer like you are seeing. Are you able to reproduce a 2+ minute delay on every attempt? 

Yu727
Excursionist
38 0 10

Thank you for your reply @vix 
I have understood and it helped me.

jarias14
Tourist
3 1 2

Does the same apply to draftOrderCreate and draftOrderRetrieve? I'm seeing a delay when making the GraphQL call to create the Order and then trying to retrieve it.

 

Thanks very much.

sillycube
Shopify Partner
783 17 132

@vix 

I am also having an issue with waiting too long for variant creations. Here is another thread I subscribed to. I just wonder if the indexing makes the variant with $0 on the cart page. Now it's just waiting too long to add the new variant to the cart.

I tried to contact Partner Support but the staff just asked me to open another thread.

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
seb87
Shopify Partner
20 0 17

I have the same problem. We developed a product option app with dynamic pricing and also have the $0 problem on the cart page. See my video here: https://community.shopify.com/c/shopify-apis-and-sdks/add-variant-and-add-this-variant-into-the-cart...

I think this is a challenge for all apps with dynamic product options and dynamic pricing. We have many options and create a new variant with our app t

Would be great if Shopify can fix this bug/delay because with this bug it is very frustrating to build new cool apps that change the product price and based on variants.