How can I query the colors that are already selected in the product in graphql?

Topic summary

A developer needs to retrieve selected color options for product variants using Shopify’s GraphQL API. Their current query fetches basic variant data (id, title, price, availableForSale) but doesn’t include the color selections visible in the Shopify admin.

Solution provided:

  • Add the selectedOptions field within the variants query
  • Structure: selectedOptions { name value }
  • Filter results where name === "Color" to isolate color values

Expected outcome:
The response will return an array of selected options for each variant, including both the option name (e.g., “Color”) and its value (e.g., “Red”, “Blue”). This allows extraction of all colors currently configured for the product.

The question appears resolved with a working code example provided.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

How can I check the colors that are already selected in the product?

For my query I am using getProduct followed by
productByHandle

My query:

Reuslt:

Color Admin:

Hi @ViniciusGG

I am from Mageplaza - Shopify solution expert.

With your current query, you aren’t fetching the selected colors for each variant yet because:

  • You’re only fetching variants { node { id, title, price, availableForSale } }.
  • You haven’t included the selectedOptions field inside each variant.

You need to update your query by adding selectedOptions inside node, like this:

variants(first: 5) {
  edges {
    node {
      id
      title
      price {
        amount
        currencyCode
      }
      availableForSale
      selectedOptions {
        name
        value
      }
    }
  }
}

Specifically, you need to:

  1. Add selectedOptions { name value } inside each variant.
  2. After that, filter for the options where name === “Color”.

Example of the response after adding selectedOptions:

{
  "data": {
    "productByHandle": {
      "variants": {
        "edges": [
          {
            "node": {
              "id": "...",
              "title": "Red Shirt",
              "selectedOptions": [
                { "name": "Color", "value": "Red" },
                { "name": "Size", "value": "M" }
              ]
            }
          },
          {
            "node": {
              "id": "...",
              "title": "Blue Shirt",
              "selectedOptions": [
                { "name": "Color", "value": "Blue" },
                { "name": "Size", "value": "L" }
              ]
            }
          }
        ]
      }
    }
  }
}

=> This way, you can easily tell that the product has the colors Red and Blue.

Please let me know if it works as expected!

Best regards!