diff --git a/src/Resolve/ResolveCollectionFactory.php b/src/Resolve/ResolveCollectionFactory.php index 58f6db6..e208f44 100644 --- a/src/Resolve/ResolveCollectionFactory.php +++ b/src/Resolve/ResolveCollectionFactory.php @@ -190,7 +190,7 @@ protected function buildPagination( 'edges' => $edgesAndCursors['edges'], 'totalCount' => $itemCount, 'pageInfo' => [ - 'endCursor' => $edgesAndCursors['cursors']['end'], + 'endCursor' => $edgesAndCursors['cursors']['last'], 'startCursor' => $edgesAndCursors['cursors']['start'], 'hasNextPage' => $edgesAndCursors['cursors']['end'] !== $edgesAndCursors['cursors']['last'], 'hasPreviousPage' => $edgesAndCursors['cursors']['first'] !== null diff --git a/src/Resolve/ResolveEntityFactory.php b/src/Resolve/ResolveEntityFactory.php index 8ffe175..95ee87f 100644 --- a/src/Resolve/ResolveEntityFactory.php +++ b/src/Resolve/ResolveEntityFactory.php @@ -120,7 +120,7 @@ public function buildPagination( 'edges' => $edgesAndCursors['edges'], 'totalCount' => $edgesAndCursors['totalCount'], 'pageInfo' => [ - 'endCursor' => $edgesAndCursors['cursors']['end'], + 'endCursor' => $edgesAndCursors['cursors']['last'], 'startCursor' => $edgesAndCursors['cursors']['start'], 'hasNextPage' => $edgesAndCursors['cursors']['end'] !== $edgesAndCursors['cursors']['last'], 'hasPreviousPage' => $edgesAndCursors['cursors']['first'] !== null diff --git a/test/Feature/Type/PageInfoTest.php b/test/Feature/Type/PageInfoTest.php index 244700b..55ace32 100644 --- a/test/Feature/Type/PageInfoTest.php +++ b/test/Feature/Type/PageInfoTest.php @@ -66,13 +66,13 @@ public function testPageInfoHasNextPage(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => $driver->completeConnection(Performance::class), + 'performances' => $driver->completeConnection(Performance::class), ], ]), ]); $query = '{ - performance (pagination: { first: 2 }) { + performances (pagination: { first: 2 }) { pageInfo { hasNextPage hasPreviousPage @@ -88,8 +88,8 @@ public function testPageInfoHasNextPage(): void $data = $result->toArray()['data']; - $this->assertTrue($data['performance']['pageInfo']['hasNextPage']); - $this->assertFalse($data['performance']['pageInfo']['hasPreviousPage']); + $this->assertTrue($data['performances']['pageInfo']['hasNextPage']); + $this->assertFalse($data['performances']['pageInfo']['hasPreviousPage']); } public function testPageInfoHasPreviousPage(): void diff --git a/test/Feature/Type/PaginationTest.php b/test/Feature/Type/PaginationTest.php index c6def66..57f8cad 100644 --- a/test/Feature/Type/PaginationTest.php +++ b/test/Feature/Type/PaginationTest.php @@ -6,6 +6,7 @@ use ApiSkeletons\Doctrine\ORM\GraphQL\Driver; use ApiSkeletonsTest\Doctrine\ORM\GraphQL\AbstractTest; +use ApiSkeletonsTest\Doctrine\ORM\GraphQL\Entity\Artist; use ApiSkeletonsTest\Doctrine\ORM\GraphQL\Entity\Performance; use GraphQL\GraphQL; use GraphQL\Type\Definition\ObjectType; @@ -47,9 +48,64 @@ public function testFirst(): void $data = $result->toArray()['data']; + $this->assertEquals($data['performance']['pageInfo']['startCursor'], $data['performance']['edges'][0]['cursor']); + $this->assertEquals($data['performance']['pageInfo']['endCursor'], $data['performance']['edges'][1]['cursor']); + $this->assertEquals(2, count($data['performance']['edges'])); } + public function testCollectionFirst(): void + { + $driver = new Driver($this->getEntityManager()); + $schema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'query', + 'fields' => [ + 'artists' => $driver->completeConnection(Artist::class), + ], + ]), + ]); + + $query = '{ + artists (pagination: { first: 1 }) { + edges { + cursor + node { + id + performances (pagination: { first: 2 }) { + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + edges { + cursor + node { + id + } + } + } + } + } + } + }'; + $result = GraphQL::executeQuery($schema, $query); + + $data = $result->toArray()['data']; + + $this->assertEquals( + $data['artists']['edges'][0]['node']['performances']['pageInfo']['startCursor'], + $data['artists']['edges'][0]['node']['performances']['edges'][0]['cursor'], + ); + $this->assertEquals( + $data['artists']['edges'][0]['node']['performances']['pageInfo']['endCursor'], + $data['artists']['edges'][0]['node']['performances']['edges'][1]['cursor'], + ); + + $this->assertEquals(2, count($data['artists']['edges'][0]['node']['performances']['edges'])); + } + public function testAfter(): void { $driver = new Driver($this->getEntityManager());