Skip to content

Commit

Permalink
Update batch reference resolvers example code snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
kfc authored Jul 31, 2024
1 parent c091948 commit 9350e60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/6/federation/reference-resolvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ final class Product implements BatchedEntityResolver
{
public function __invoke(array $representations): iterable
{
$products = ProductRepository::byIDs(Arr::pluck($representations, 'id'));
$products = ProductRepository::byIDs(Arr::pluck($representations, 'id'))->keyBy('id');

$result = [];
foreach ($representations as $key => $representation) {
$result[$key] = $products->firstWhere('id', $representation['id']);
$result[$key] = $products->get($representation['id']);
}

return $result;
Expand Down
4 changes: 2 additions & 2 deletions docs/master/federation/reference-resolvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ final class Product implements BatchedEntityResolver
{
public function __invoke(array $representations): iterable
{
$products = ProductRepository::byIDs(Arr::pluck($representations, 'id'));
$products = ProductRepository::byIDs(Arr::pluck($representations, 'id'))->keyBy('id');

$result = [];
foreach ($representations as $key => $representation) {
$result[$key] = $products->firstWhere('id', $representation['id']);
$result[$key] = $products->get($representation['id']);
}

return $result;
Expand Down

0 comments on commit 9350e60

Please sign in to comment.