Couldn't get variant asap after it is created

Solved
Highlighted
Excursionist
38 0 3

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?

 

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
491 97 88

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? 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


1 Like
Highlighted
Excursionist
38 0 3

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

0 Likes
Highlighted
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.

0 Likes