Skip to content

(Magento 2.4) Add custom filtering to product attribute in graphql

I’d like to add a filter in the graphQl product query like this

products(
        pageSize: 5
        currentPage: 1
        filter: {
            status: { eq: "1" }
            catalog_rules: { id: { eq: "1" } }
            category_id: { eq: "2" }
        }
    ){
        total_count
        items {
            id
            sku
            name
            catalog_rules {
                total_count
                items {
                    end_date
                    id
                    name
                    start_date
                    status
                    web_site
                }
            }
        }
    }

Basically I want to retrieve the catalog price rules applied to a product. I created a module correctly and registered it, extending the graphQl Magento schema, but in the resolver I can’t get the “catalog_rules” field, neither the “filter” field, what am I doing wrong?