Catalog GraphQL Batching
Module: Magenx_CatalogGraphQlBatch · no settings, no new fields
Some stock Magento GraphQL product fields run one database query per product. On a page of 24 products that is dozens of extra queries. This module loads them once for the whole list instead. Enable it, and product grids and related-product lists get faster. Nothing changes for the storefront.
What it batches
Section titled “What it batches”| Field | Stock Magento | With this module |
|---|---|---|
price_range (catalog price rule prices) | 1 query per product | 1 query per list |
price_range (tier prices) | 1 query per product | 1 query per list |
rating_summary | 1 query per product | 1 query per list |
review_count | 1 query per product | 1 query per list |
The values are exactly what stock Magento returns: same store, website, date and customer group. If the price preload fails, it is logged and Magento falls back to its own per-product lookups.
Not covered:
- Configurable products still find their lowest-priced child one product at a time.
- For signed-in customers, catalog rule prices are still recomputed per product by stock Magento.
stock_statusis unchanged.
User flows
Section titled “User flows”Category grid
- The storefront asks for 24 products with prices and ratings.
- After the list is loaded, promotion and quantity-break prices for all 24 are fetched in one lookup each.
- Rating summaries and review counts for all 24 are fetched in one lookup each.
- The response equals the response without bulk loading.
These always hold:
- Every value equals the per-product result for the same product, store, website, date and customer group.
- The storefront contract is unchanged.
Edge cases
Section titled “Edge cases”| Situation | What happens |
|---|---|
| No price field requested. | No price bulk load. |
| Product without a promotion price. | Regular price, as before. |
| Bulk load fails. | Warning logged; correct values via the per-product path. |
| Product without reviews. | Rating 0, count 0. |
| Store-local date differs from server date. | Promotion price for the store-local date. |
| Promotion only for a "Wholesale" group. | Wholesale customer sees it; guest does not. |
Who it applies to
Section titled “Who it applies to”- Every product list produced by the storefront API.
Out of scope
Section titled “Out of scope”- The "lowest-priced variant" lookup for configurable products.
- Promotion price recalculation done per product for signed-in customers.
- Stock status.
- Caching across requests.
Install
Section titled “Install”composer require magenxcommerce/module-catalog-graph-ql-batchbin/magento module:enable Magenx_CatalogGraphQlBatchbin/magento setup:upgradebin/magento setup:di:compile # production mode onlybin/magento cache:flush- PHP
~8.4.0||~8.5.0, Magento 2.4.8.
Check it works
Section titled “Check it works”Turn on Magento’s query log, load one category page or product page, and count the tables:
bin/magento dev:query-log:enable --include-all-queries=true --query-time-threshold=0 --include-call-stack=false: > var/debug/db.log# load one category page or product page, then:grep -oE 'FROM `[a-z0-9_]+`' var/debug/db.log | sort | uniq -c | sort -rn | head -20bin/magento dev:query-log:disablecatalogrule_product_price, catalog_product_entity_tier_price, review_entity_summary and review should appear once per product list, not once per product.
GraphQL
Section titled “GraphQL”No new fields. The module re-declares two stock fields so they can be resolved for a whole list:
Fields added to Magento types
| Field | Type | Description |
|---|---|---|
ProductInterface.rating_summary | Float! | The average of all the ratings given to the product. |
ProductInterface.review_count | Int! | The total count of all the reviews given to the product. |
Glossary
Section titled “Glossary”| Term | Meaning |
|---|---|
| Product list | One set of products the API returns together (a search page or a recommendation rail). |
| Bulk load | Fetching a value for the whole list before per-product fields are produced. |
| Promotion price | Price after catalog promotions for the product, website, customer group and date. |
| Quantity-break price | Price that applies from a minimum quantity. |