Skip to content

Magento 2 Graphql: custom filter products not working

I want to add a custom filter (Stock status filter) to products like this one but it’s not working.
How to filter product collection with default graphql products query in Magento 2

I used XDebug to see what was happening and used breakpoint in the constructor, it was ok and my breakpoint worked fine, but the apply function is not working. it looks like it’s jumping out from my custom filter class.

this is my graphql/di.xml file:

<virtualType name="MagentoCatalogModelApiSearchCriteriaCollectionProcessorProductFilterProcessor" type="MagentoEavModelApiSearchCriteriaCollectionProcessorFilterProcessor">
<arguments>
    <argument name="customFilters" xsi:type="array">
        <item name="is_in_stock" xsi:type="object">
            SZKProductGraphQlModelResolverProductsSearchCriteriaCollectionProcessorFilterProcessorStockStatusFilter
        </item>
    </argument>
</arguments>