As shopify has notified, to migrate the shopify product api’s to graphql api’s,
and i need to create product, where we are setting product name and sku
can’t we do this with graphql api?
The SKU is set on InventoryItem
Hi @Navneet_Chauhan! You can absolutely set SKU using the GraphQL API.
As @Luke mentioned, SKU is a property of the variant (specifically, its associated InventoryItem), not the product itself. So you set it when defining variants.
The easiest approach is using the productSet mutation, which lets you create a product with variants and SKUs in a single call:
mutation createProductWithSKU {
productSet(
synchronous: true,
input: {
title: "My Product",
productOptions: [
{
name: "Size",
values: [
{ name: "Small" },
{ name: "Large" }
]
}
],
variants: [
{
optionValues: [{ optionName: "Size", name: "Small" }],
sku: "PROD-SM-001",
price: "19.99"
},
{
optionValues: [{ optionName: "Size", name: "Large" }],
sku: "PROD-LG-001",
price: "24.99"
}
]
}
) {
product {
id
title
variants(first: 10) {
nodes {
id
sku
price
}
}
}
userErrors {
field
message
}
}
}
The productSet mutation is designed for syncing product data from external sources and is the recommended approach for the REST to GraphQL migration. See Sync product data for more details.
If you’re creating a product first with productCreate and then adding variants separately, you’d use productVariantsBulkCreate and pass the SKU via the inventoryItem input field:
inventoryItem: {
sku: "YOUR-SKU"
}
But productSet is generally simpler since it handles everything in one call.