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:
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:
selectedOptions field within the variants queryselectedOptions { name value }name === "Color" to isolate color valuesExpected 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.
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 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:
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!