1
votes

We are facing challenges while updating product options in product variants as options fields in GraphQL and Rest API are totally different. Below is the screen-shot:

GraphQL: enter image description here

REST APIs: enter image description here

We are using GraphQL to mutate product variant. So our challenge is, how can we send three different options (like, large, blue, paper) to product variant that make one variant as it takes only one [String!] value. Whereas in REST APIs, there are three different options (option1, option2, option3) along with Default Title.

Also, if possible can anyone share a dummy mutation request for this?

Below are the links that we are referring to:

Update Product Variant: https://shopify.dev/docs/admin-api/graphql/reference/mutation/productvariantupdate?api[version]=2020-04

Update Product: https://shopify.dev/docs/admin-api/graphql/reference/mutation/productupdate?api[version]=2020-04

1

1 Answers

2
votes

Well, it actually takes an array of strings ([String!]), not a single string value. So you need to pass it like that ["Large", "Blue", "Paper"], see detailed mutation request below:

Query

mutation productVariantUpdate($input: ProductVariantInput!) {
  productVariantUpdate(input: $input) {
    productVariant {
      id,
      selectedOptions {
          name,
          value
      }
    }
    userErrors {
      field
      message
    }
  }
}

Variables

{
  "input": {
    "id": "gid://shopify/ProductVariant/31886472609857",
    "options": ["Large", "Blue", "Paper"]
  }
}