How to get custom product attributes values using graphQl queries in magento 2.3?
-
09-03-2021 - |
Question
I want to get the values for custom product attribute in product details page. I am using below GrapgQl query to get the values. i am passing the name as the argument. How can i get the products attributes.
{
products(filter:{name: {eq: "Joust Duffle Bag"}}
){
items{
id
sku
special_price
description{ html}
short_description{ html}
meta_title
meta_keyword
meta_description
options_container
type_id
image{ url label }
small_image{ url label }
thumbnail{ url label }
price{
regularPrice{
amount{
value
currency
}
}
}
}
}
}
Solution
After some searches we dont need any special query methods to retriew custom attributes. We can just pass the custom attribute code to the query.
EX - our custom attribute code is publisher just pass it in the query.
{
products(filter:{name: {eq: "Joust Duffle Bag"}}
){
items{
id
sku
publisher
price{
regularPrice{
amount{
value
currency
}
}
}
}
}
}
to get the custom attribute values and label if it was the multiple select or select type refer How to get product attribute value, label using GraphQl in Magento 2.3?
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange