A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
We are using the admin GraphQL API to create products, and everything works well except for occasional race conditions that result in multiple products sharing the same SKU. To address this, we attempted to execute a query before creation to check for an existing variant with the same SKU. Here is the query we are using:
query ($sku: String){ productVariants(first: 1, query: $sku) { edges { node { title id sku } } } }
However, we've encountered an issue where the API does not return the recently created product if it was created in less than 10 seconds (as tested). Unfortunately, this approach is not effective for our use case.
Questions:
Any insights or suggestions would be greatly appreciated!
Hey ShaneOH!
The race condition you're experiencing when creating products using the GraphQL API can be a common challenge in concurrent programming. I've made a note of some insights and suggestions to address this challenge below:
Alternative Approaches to Avoid Race Conditions:
a. Retry Strategy:
b. Unique SKU Enforcement:
c. Webhooks and Event Driven:
d. Custom App Logic:
Considerations...in my opinion / experience:
Curious what you end up proceeding with! Let me know how it goes!
Hi @Jclewis1989 We are decided what to do.
Unfortunately none of your suggestions seems to fit our necessities
Thanks