Skip to content

Commit 3b5d77f

Browse files
authored
Merge pull request #2061 from epourail/fix-totalitems-on-empty-collection
Initialize the 'totalCount' property to the default value to 0.0
2 parents d9c5d0c + 745b6ab commit 3b5d77f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/GraphQl/Resolver/Factory/CollectionResolverFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
107107
$offset = 1 + (int) $after;
108108
}
109109

110-
$data = ['edges' => [], 'pageInfo' => ['endCursor' => null, 'hasNextPage' => false]];
110+
$data = ['totalCount' => 0.0, 'edges' => [], 'pageInfo' => ['endCursor' => null, 'hasNextPage' => false]];
111111
if ($collection instanceof PaginatorInterface && ($totalItems = $collection->getTotalItems()) > 0) {
112112
$data['pageInfo']['endCursor'] = base64_encode((string) ($totalItems - 1));
113113
$data['pageInfo']['hasNextPage'] = $collection->getCurrentPage() !== $collection->getLastPage() && (float) $collection->count() === $collection->getItemsPerPage();

tests/GraphQl/Resolver/Factory/CollectionResolverFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testCreateCollectionResolverNoCollection(bool $paginationEnabled
5454
public function paginationProvider(): array
5555
{
5656
return [
57-
[true, ['edges' => [], 'pageInfo' => ['endCursor' => null, 'hasNextPage' => false]]],
57+
[true, ['totalCount' => 0.0, 'edges' => [], 'pageInfo' => ['endCursor' => null, 'hasNextPage' => false]]],
5858
[false, []],
5959
];
6060
}
@@ -133,6 +133,7 @@ public function testCreateCollectionResolver(string $cursor, array $expectedCurs
133133

134134
$this->assertEquals(
135135
[
136+
'totalCount' => 0.0,
136137
'edges' => [['node' => 'normalizedObject1', 'cursor' => $expectedCursors[0]], ['node' => 'normalizedObject2', 'cursor' => $expectedCursors[1]]],
137138
'pageInfo' => ['endCursor' => null, 'hasNextPage' => false],
138139
],

0 commit comments

Comments
 (0)