cancel
Showing results for 
Search instead for 
Did you mean: 

How to add custom product attribute in graphQL?

SOLVED

How to add custom product attribute in graphQL?

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?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to add custom product attribute in graphQL?

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

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

View solution in original post

4 REPLIES 4

Re: How to add custom product attribute in graphQL?

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

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: How to add custom product attribute in graphQL?

hello @gaurav_harsh1 

Thank you for your answer. But I think I still need to add this new attribute in my schema.graphql file ?

Re: How to add custom product attribute in graphQL?

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!

Problem solved? Click Accept as Solution!

Re: How to add custom product attribute in graphQL?

@kenwhippcc5de5 

 

Yes, you need to pass the custom attribute value which you want to fetch.

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy