A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm trying to follow the guide to sync data from an external source using the productSet migration https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/sync-data
My mutation looks like this:
mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
}
productSetOperation {
id
status
userErrors {
code
field
message
}
}
userErrors {
code
field
message
}
}
}
I want to sync title, description and price so my productSet looks like this.
const productSet = {
title: product.name,
descriptionHtml: product.description,
vendor: product.vendor,
productOptions: [{
name: "Dummy",
position: 1,
values: [{
name: "High"
}]
}],
variants: [{
optionValues: [{
optionName: "Dummy",
name: "High"
}],
price: product.price
}]
}
I don't want the dummy "productOptions" to be needed as it shows up on the product listing. But if i omit productOptions/optionValues i get an error like:
Variable $productSet of type ProductSetInput! was provided invalid value for variants.0.optionValues (Expected value to not be null)
How can i create a simple product with one price and no options/variants?
Hi Matthew,
Using the same mutation you could structure your variables to be something like this:
{
"productSet": {
"title": "Sample Product",
"descriptionHtml": "<p>This is a sample product description.</p>",
"vendor": "Sample Vendor",
"productOptions": [
{
"name": "Title",
"values": [
{"name": "Default Title"}
]
}
],
"variants": [
{
"price": "19.99",
"optionValues": [
{
"optionName": "Title",
"name": "Default Title"
}
]
}
]
},
"synchronous": false
}
Would this work for you?
Liam | Developer Advocate @ 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
yes that does work. i dont totally understand why my version gave me a selector for selecting the "Dummy" field on the product page, but your "Title" product option is invisible?
Hi Liam,
Although this works, all products are created with one variant instead of the (normally hidden) default variant. This means that some themes won't show a quick buy button. Also, some themes show the option names and values on the product detail page, which normally is just 'Default title'.
Is there any way that productSet can be used to import simple products (only default variant) without having an option value and option name?
@Liam Thanks for this response - but this doesn't create a default variant - see here for the test:
https://community.shopify.com/c/graphql-basics-and/how-do-you-create-a-product-with-the-default-vari...
Do you have any insight as to how to create a default variant with productSet?
EDIT: never mind, the issue was capitalisation:
The correct value is related to capitalisation - it needs to be "Default Title" not "Default title" - to generate a default variant