Skip to content

Commit

Permalink
Corrected collection limits
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed May 27, 2023
1 parent 415611b commit d1a7e46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/Resolve/ResolveCollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public function get(Entity $entity): Closure

$entityClass = ClassUtils::getRealClass($source::class);

$targetClassName = (string) $this->entityManager->getMetadataFactory()
->getMetadataFor($entityClass)
->getAssociationTargetClass($info->fieldName);

$collectionMetadata = $this->entityManager->getMetadataFactory()
->getMetadataFor(
(string) $this->entityManager->getMetadataFactory()
->getMetadataFor($entityClass)
->getAssociationTargetClass($info->fieldName),
);
->getMetadataFor($targetClassName);

return $this->buildPagination(
$entityClass,
$targetClassName,
$args['pagination'] ?? [],
$collection,
$this->buildCriteria($args['filter'] ?? [], $collectionMetadata),
Expand Down Expand Up @@ -131,7 +131,7 @@ private function buildCriteria(array $filter, ClassMetadata $collectionMetadata)
* @return mixed[]
*/
private function buildPagination(
string $entityClass,
string $targetClassName,
array $pagination,
PersistentCollection $collection,
Criteria $criteria,
Expand Down Expand Up @@ -163,7 +163,7 @@ private function buildPagination(

$itemCount = count($collection->matching($criteria));

$offsetAndLimit = $this->calculateOffsetAndLimit($entityClass, $paginationFields, $itemCount);
$offsetAndLimit = $this->calculateOffsetAndLimit($targetClassName, $paginationFields, $itemCount);
if ($offsetAndLimit['offset']) {
$criteria->setFirstResult($offsetAndLimit['offset']);
}
Expand Down Expand Up @@ -246,11 +246,11 @@ protected function buildEdgesAndCursors(Collection $items, array $offsetAndLimit
*
* @return array<string, int>
*/
protected function calculateOffsetAndLimit(string $entityClass, array $paginationFields, int $itemCount): array
protected function calculateOffsetAndLimit(string $targetClassName, array $paginationFields, int $itemCount): array
{
$offset = 0;

$limit = $this->metadata[$entityClass]['limit'];
$limit = $this->metadata[$targetClassName]['limit'];

if (! $limit) {
$limit = $this->config->getLimit();
Expand Down
3 changes: 2 additions & 1 deletion test/Feature/Metadata/LimitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function testEntityLimit(): void

$data = $result->toArray()['data'];
$this->assertEquals(2, count($data['artist']['edges']));
$this->assertEquals(9, count($data['artist']['edges'][0]['node']['performances']['edges']));
$this->assertEquals(5, count($data['artist']['edges'][0]['node']['performances']['edges']));
$this->assertEquals(2, count($data['artist']['edges'][1]['node']['performances']['edges']));
}
}

0 comments on commit d1a7e46

Please sign in to comment.