I have a new product attribute, I added this attribute in backend, I also assign this attribute value in product edit page.
But how can I get this attribute value by product query in graphQL such as "filter" and "search" ? just need to add in the schema file? What else that I need to do?
Solved! Go to Solution.
Hello @kenwhippcc5de5
You don't need any special query methods to retrieve custom attributes. We can just pass the custom attribute code to the query. And also for filtering you can simple pass the attribute name, please follow this documentation :
https://devdocs.magento.com/guides/v2.4/graphql/custom-filters.html
Hello @kenwhippcc5de5
You don't need any special query methods to retrieve custom attributes. We can just pass the custom attribute code to the query. And also for filtering you can simple pass the attribute name, please follow this documentation :
https://devdocs.magento.com/guides/v2.4/graphql/custom-filters.html
hello @gaurav_harsh1
Thank you for your answer. But I think I still need to add this new attribute in my schema.graphql file ?
Hi @kenwhippcc5de5
After some searches we don't need any special query methods to retrieve custom attributes. We can just pass the custom attribute code to the query.
Example - 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?
It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!
Yes, you need to pass the custom attribute value which you want to fetch.