Skip to content

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.

FieldStock MagentoWith this module
price_range (catalog price rule prices)1 query per product1 query per list
price_range (tier prices)1 query per product1 query per list
rating_summary1 query per product1 query per list
review_count1 query per product1 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_status is unchanged.

Category grid

  1. The storefront asks for 24 products with prices and ratings.
  2. After the list is loaded, promotion and quantity-break prices for all 24 are fetched in one lookup each.
  3. Rating summaries and review counts for all 24 are fetched in one lookup each.
  4. 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.
SituationWhat 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.
  • Every product list produced by the storefront API.
  • The "lowest-priced variant" lookup for configurable products.
  • Promotion price recalculation done per product for signed-in customers.
  • Stock status.
  • Caching across requests.
Terminal window
composer require magenxcommerce/module-catalog-graph-ql-batch
bin/magento module:enable Magenx_CatalogGraphQlBatch
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.

Turn on Magento’s query log, load one category page or product page, and count the tables:

Terminal window
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 -20
bin/magento dev:query-log:disable

catalogrule_product_price, catalog_product_entity_tier_price, review_entity_summary and review should appear once per product list, not once per product.

No new fields. The module re-declares two stock fields so they can be resolved for a whole list:

Fields added to Magento types

FieldTypeDescription
ProductInterface.rating_summaryFloat!The average of all the ratings given to the product.
ProductInterface.review_countInt!The total count of all the reviews given to the product.
TermMeaning
Product listOne set of products the API returns together (a search page or a recommendation rail).
Bulk loadFetching a value for the whole list before per-product fields are produced.
Promotion pricePrice after catalog promotions for the product, website, customer group and date.
Quantity-break pricePrice that applies from a minimum quantity.