Magento2 GraphQL Stock Filter Module
Extend Magento 2 GraphQL with stock status filtering for more efficient headless storefronts and better SEO handling.
At Mage2, our Magento developers are constantly working on creating new modules to help extend Magento’s out-of-the-box functionality. One limitation we came across is that Magento 2 GraphQL doesn’t include a built-in stock status filter. This makes it harder for developers to work efficiently when building headless Magento 2 storefronts, since filtering products by availability is a fundamental need.
To address this gap, we’ve created a new open-source module that adds stock status filtering support for GraphQL queries, making it easier and faster to build headless Magento experiences.
Why This Matters
Magento does include a setting to “Hide Out of Stock Products from the frontend”. At first glance, this might seem useful — but in practice, it can cause serious SEO problems.
When an out-of-stock product is hidden, its page effectively disappears from the site. If Google has already indexed that page, it will start returning 404 errors. Over time, this can:
- Damage your SEO rankings
- Reduce organic traffic
- Break backlinks from other websites pointing to those products
For example, imagine you’re selling a popular limited-edition backpack. It gets featured in a blog post and shared widely, earning you dozens of backlinks. As soon as it goes out of stock, Magento hides the page, and Google sees a 404. Not only do you lose the product’s ranking in search results, but you also throw away all the SEO authority those backlinks gave you.
With our GraphQL Stock Filter, you don’t have to hide products from Google. Instead, you can keep the product pages live for SEO while controlling exactly how products appear in your headless storefront (e.g., only showing “in-stock” items in category listings). This means you keep your SEO value intact while still giving customers a smooth browsing experience.
Key Features
GraphQL Stock Filtering
Multiple Value Formats
Universal Compatibility
Performance Focused
Robust Error Handling
Magento Standards
Installation
Stores → Configuration → Catalog → Inventory → Display Out of Stock Products.
Via Composer (Recommended)
composer require mage2au/module-graphql-stock-filter
php bin/magento module:enable Mage2AU_GraphQLStockFilter
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush
Manual Installation
- Download or clone the repository
- Copy files to: app/code/Mage2AU/GraphQLStockFilter/
- Enable and set up the module:
php bin/magento module:enable Mage2AU_GraphQLStockFilter
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush
Usage
Basic Query – In-Stock Products
query {
products(filter: { stock_status: { eq: "IN_STOCK" } }) {
items {
sku
name
stock_status
price_range {
minimum_price {
regular_price {
value
currency
}
}
}
}
total_count
}
}
Advanced Query – Combine Filters
query {
products(
filter: {
sku: { match: "24-MB" }
stock_status: { eq: "IN_STOCK" }
price: { from: "10", to: "100" }
}
pageSize: 20
currentPage: 1
) {
items {
sku
name
stock_status
}
total_count
}
}
FAQs
What is the Magento2 GraphQL Stock Filter module?
It’s a free open-source module developed by Mage2 that lets you filter products by stock status (IN_STOCK or OUT_OF_STOCK) directly in GraphQL queries.