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

Filter products by stock status in GraphQL queries

Multiple Value Formats

Supports both string (IN_STOCK/OUT_OF_STOCK) and numeric (1/0) values

Universal Compatibility

Works with both traditional single-stock and Multi-Source Inventory (MSI) setups

Performance Focused

Efficient database joins to minimise query overhead

Robust Error Handling

Includes logging for debugging

Magento Standards

Built following Magento 2 coding standards and best practices

Installation

Note: Make sure Display Out of Stock Products is set to Yes in:
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
  1. Download or clone the repository
  2. Copy files to: app/code/Mage2AU/GraphQLStockFilter/
  3. 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.

Why do I need this module?
By default, Magento 2 does not allow stock filtering via GraphQL. This module makes headless storefronts more efficient and ensures product pages remain visible for SEO while still letting you hide out-of-stock items from category pages and other product listing pages.
Does it work with Multi-Source Inventory (MSI)?
Yes. The module supports both single-stock and MSI setups.
Is it really free?
Yes! It’s released under the MIT License, meaning you can use, modify, and contribute to it freely.

Looking for Magento Experts?

At Mage2, we help businesses design, develop, and optimise their Magento stores for performance, scalability, and growth.

This field is for validation purposes and should be left unchanged.
Name(Required)