From b52a8e675996d25c1b165a25dba3f6c730baf690 Mon Sep 17 00:00:00 2001 From: Alexander Lelidis Date: Mon, 30 Dec 2024 07:32:21 -0500 Subject: [PATCH] chore: return reviews for a product in example reviews subgraph (#994) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running queries like the following before the is pr no reviews for a product were returned. ```graphql { me { username id reviews { body product { upc } } } topProducts(first: 2) { upc reviews { body } } } ``` Co-authored-by: Sergiy πŸ‡ΊπŸ‡¦ <818351+devsergiy@users.noreply.github.com> --- examples/federation/reviews/graph/entity.resolvers.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/federation/reviews/graph/entity.resolvers.go b/examples/federation/reviews/graph/entity.resolvers.go index 213bd290b1..7043d174a5 100644 --- a/examples/federation/reviews/graph/entity.resolvers.go +++ b/examples/federation/reviews/graph/entity.resolvers.go @@ -13,8 +13,16 @@ import ( // FindProductByUpc is the resolver for the findProductByUpc field. func (r *entityResolver) FindProductByUpc(ctx context.Context, upc string) (*model.Product, error) { + var productReviews []*model.Review + for _, review := range reviews { + if review.Product.Upc == upc { + productReviews = append(productReviews, review) + } + } + return &model.Product{ - Upc: upc, + Upc: upc, + Reviews: productReviews, }, nil }