Skip to main content

Create Product

Create a new product with variants and options.
mutation CreateProduct {
  createProduct(
    data: {
      title: "Vintage T-Shirt"
      handle: "vintage-tee"
      subtitle: "Classic cotton tee"
      status: "draft"
      discountable: true
      productType: { connect: { id: "..." } }
      productCategory: { connect: { id: "..." } }
      productCollection: { connect: { id: "..." } }
      productTags: {
        connect: [{ id: "..." }]
      }
    }
  ) {
    id
    title
    handle
    status
  }
}

Parameters

title
string
required
Product title
handle
string
URL-friendly identifier (auto-generated from title if not provided)
subtitle
string
Product subtitle or tagline
description
document
Rich text product description
status
string
Product status: draft, proposed, published, rejectedDefault: draft
isGiftcard
boolean
Whether this is a gift card productDefault: false
discountable
boolean
Whether discounts can be applied to this productDefault: true
productType
relation
Connect to an existing product type
productType: { connect: { id: "..." } }
productCollection
relation
Connect to a product collection
productCollection: { connect: { id: "..." } }
productCategory
relation
Connect to a product category
productCategory: { connect: { id: "..." } }
productTags
array
Connect multiple product tags
productTags: { connect: [{ id: "..." }, { id: "..." }] }
salesChannels
array
Connect sales channels where product is available
salesChannels: { connect: [{ id: "..." }] }

Update Product

Update an existing product.
mutation UpdateProduct {
  updateProduct(
    where: { id: "..." }
    data: {
      title: "Updated Title"
      status: "published"
      subtitle: "New subtitle"
    }
  ) {
    id
    title
    status
    updatedAt
  }
}

Update Product Images

mutation UpdateProductImages {
  updateProduct(
    where: { id: "..." }
    data: {
      productImages: {
        create: [
          {
            imagePath: "/uploads/product-1.jpg"
            sortOrder: 0
          }
        ]
      }
    }
  ) {
    id
    productImages {
      id
      imagePath
      sortOrder
    }
  }
}

Update Product Variants

mutation UpdateProductVariants {
  updateProduct(
    where: { id: "..." }
    data: {
      productVariants: {
        create: [
          {
            title: "Small / Blue"
            sku: "VT-SM-BLU"
            inventoryQuantity: 100
            manageInventory: true
            allowBackorder: false
          }
        ]
        update: [
          {
            where: { id: "..." }
            data: { inventoryQuantity: 50 }
          }
        ]
      }
    }
  ) {
    id
    productVariants {
      id
      title
      sku
      inventoryQuantity
    }
  }
}

Delete Product

Delete a product and its associated data.
mutation DeleteProduct {
  deleteProduct(where: { id: "..." }) {
    id
    title
  }
}
Deleting a product will also delete:
  • Product variants
  • Product images
  • Product options and values
  • Money amounts (pricing)
Orders containing this product will retain a snapshot and are not affected.

Create Product with Variants

Complete example creating a product with options and variants.
mutation CreateProductWithVariants {
  createProduct(
    data: {
      title: "Classic T-Shirt"
      handle: "classic-tee"
      status: "published"
      discountable: true
      
      # Create product options
      productOptions: {
        create: [
          {
            name: "Size"
            values: {
              create: [
                { value: "Small" }
                { value: "Medium" }
                { value: "Large" }
              ]
            }
          }
          {
            name: "Color"
            values: {
              create: [
                { value: "Black" }
                { value: "White" }
                { value: "Blue" }
              ]
            }
          }
        ]
      }
      
      # Create variants for each combination
      productVariants: {
        create: [
          {
            title: "Small / Black"
            sku: "CT-SM-BLK"
            inventoryQuantity: 50
            manageInventory: true
            moneyAmounts: {
              create: [
                {
                  amount: 2999
                  currency: { connect: { code: "USD" } }
                }
              ]
            }
          }
          {
            title: "Medium / Black"
            sku: "CT-MD-BLK"
            inventoryQuantity: 75
            manageInventory: true
            moneyAmounts: {
              create: [
                {
                  amount: 2999
                  currency: { connect: { code: "USD" } }
                }
              ]
            }
          }
        ]
      }
      
      # Add product images
      productImages: {
        create: [
          {
            imagePath: "/uploads/tee-front.jpg"
            sortOrder: 0
          }
          {
            imagePath: "/uploads/tee-back.jpg"
            sortOrder: 1
          }
        ]
      }
    }
  ) {
    id
    title
    handle
    productOptions {
      id
      name
      values { value }
    }
    productVariants {
      id
      title
      sku
      inventoryQuantity
      moneyAmounts {
        amount
        currency { code }
      }
    }
  }
}

Bulk Operations

Publish Multiple Products

mutation PublishProducts {
  updateProducts(
    where: [
      { id: "prod_1" }
      { id: "prod_2" }
      { id: "prod_3" }
    ]
    data: {
      status: "published"
    }
  ) {
    id
    title
    status
  }
}

Update Product Category

mutation UpdateCategory {
  updateProducts(
    where: [
      { id: "prod_1" }
      { id: "prod_2" }
    ]
    data: {
      productCategory: { connect: { id: "cat_new" } }
    }
  ) {
    id
    title
    productCategory { name }
  }
}

Product Variants

Create Variant

mutation CreateVariant {
  createProductVariant(
    data: {
      product: { connect: { id: "..." } }
      title: "XL / Red"
      sku: "CT-XL-RED"
      barcode: "123456789"
      inventoryQuantity: 100
      manageInventory: true
      allowBackorder: false
      
      # Pricing
      moneyAmounts: {
        create: [
          {
            amount: 3499
            currency: { connect: { code: "USD" } }
          }
        ]
      }
      
      # Dimensions
      measurements: {
        create: [
          { type: "weight", value: 200, unit: "g" }
          { type: "length", value: 30, unit: "cm" }
          { type: "width", value: 20, unit: "cm" }
          { type: "height", value: 2, unit: "cm" }
        ]
      }
      
      # Option values
      productOptions: {
        connect: [
          { id: "optval_size_xl" }
          { id: "optval_color_red" }
        ]
      }
    }
  ) {
    id
    title
    sku
    inventoryQuantity
  }
}

Update Variant Inventory

mutation UpdateInventory {
  updateProductVariant(
    where: { id: "..." }
    data: {
      inventoryQuantity: 75
    }
  ) {
    id
    sku
    inventoryQuantity
  }
}

Update Variant Pricing

mutation UpdateVariantPricing {
  updateProductVariant(
    where: { id: "..." }
    data: {
      moneyAmounts: {
        update: [
          {
            where: { id: "..." }
            data: { amount: 2499 }
          }
        ]
        create: [
          {
            amount: 24
            currency: { connect: { code: "EUR" } }
            region: { connect: { id: "..." } }
          }
        ]
      }
    }
  ) {
    id
    moneyAmounts {
      amount
      currency { code }
      region { name }
    }
  }
}

Access Control

Product mutations require the canManageProducts permission. Only authenticated users with this permission can create, update, or delete products.

Validation Rules

  • Title: Required field
  • Handle: Must be unique across all products
  • SKU: Must be unique across all variants (if provided)
  • Inventory: Cannot be negative when manageInventory is true
  • Pricing: Amount must be a positive integer (cents)

Best Practices

Create SKU patterns that include product code, size, and color:
  • TSHIRT-SM-BLK instead of T1
  • Makes inventory management easier
  • Helps prevent fulfillment errors
  • Use draft for products still being configured
  • Use proposed for products awaiting approval
  • Use published for products ready to sell
  • Use rejected for discontinued products
  • Enable manageInventory for physical products
  • Set allowBackorder based on your fulfillment capabilities
  • Update inventory via stock movements for audit trails
  • Include front, back, and detail shots
  • Use sortOrder to control display order
  • First image becomes the product thumbnail

Product Queries

Query products and variants

Product Management

Admin UI for products

Build docs developers (and LLMs) love