query.graph.
Before you begin
Pick the approach that matches what should count toward the number:- Rating helpers: one SQL query per call; counts
pending,rejected, and soft deleted reviews too - Published only: loads the target’s reviews with
query.graphand averages thepublishedones
1
Return a store's average from the service
Resolve the service with The first argument is
MercurModules.REVIEW and call getAvgRating:src/api/store/sellers/[id]/rating/route.ts
"product" or "seller", the second the target’s id. The method returns a numeric string, or null when the target has no reviews, so the route converts it to a number.2
Average published reviews only
Load the product’s linked reviews with
query.graph and average the published ones:src/api/store/products/[id]/rating/route.ts
reviews is the alias the product to review link adds to a product. Soft deleted reviews don’t come back from query.graph, so they never count.Rate every product or store in one query
For list pages,getProductsWithRating and getSellersWithRating return every row of the product or seller table with its average joined in:
rating string, or null for rows without reviews. The helpers take no filters or pagination and include soft deleted products and sellers, so filter the result before you return it.