-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from TomHAnderson/feature/pageinfo
startCursor and hasPreviousPage added to PageInfo
- Loading branch information
Showing
9 changed files
with
215 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiSkeletons\Doctrine\GraphQL\Type; | ||
|
||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
class PageInfo extends ObjectType | ||
{ | ||
public function __construct() | ||
{ | ||
$configuration = [ | ||
'name' => 'PageInfo', | ||
'description' => 'Page information', | ||
'fields' => [ | ||
'startCursor' => Type::nonNull(Type::string()), | ||
'endCursor' => Type::nonNull(Type::string()), | ||
'hasPreviousPage' => Type::nonNull(Type::boolean()), | ||
'hasNextPage' => Type::nonNull(Type::boolean()), | ||
], | ||
]; | ||
|
||
parent::__construct($configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
namespace ApiSkeletonsTest\Doctrine\GraphQL\Feature\Resolve; | ||
|
||
use ApiSkeletons\Doctrine\GraphQL\Config; | ||
use ApiSkeletons\Doctrine\GraphQL\Driver; | ||
use ApiSkeletonsTest\Doctrine\GraphQL\AbstractTest; | ||
use ApiSkeletonsTest\Doctrine\GraphQL\Entity\Performance; | ||
use GraphQL\GraphQL; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
use GraphQL\Type\Schema; | ||
|
||
use function count; | ||
|
||
class PageInfoTest extends AbstractTest | ||
{ | ||
public function testPageInfo(): void | ||
{ | ||
$driver = new Driver($this->getEntityManager()); | ||
$schema = new Schema([ | ||
'query' => new ObjectType([ | ||
'name' => 'query', | ||
'fields' => [ | ||
'performance' => [ | ||
'type' => $driver->connection($driver->type(Performance::class)), | ||
'args' => [ | ||
'filter' => $driver->filter(Performance::class), | ||
], | ||
'resolve' => $driver->resolve(Performance::class), | ||
], | ||
], | ||
]), | ||
]); | ||
|
||
$query = '{ | ||
performance { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
startCursor | ||
endCursor | ||
} | ||
edges { | ||
cursor | ||
node { | ||
id | ||
} | ||
} | ||
} | ||
}'; | ||
$result = GraphQL::executeQuery($schema, $query); | ||
|
||
$data = $result->toArray()['data']; | ||
|
||
$this->assertFalse($data['performance']['pageInfo']['hasNextPage']); | ||
$this->assertFalse($data['performance']['pageInfo']['hasPreviousPage']); | ||
$this->assertEquals( | ||
$data['performance']['edges'][0]['cursor'], | ||
$data['performance']['pageInfo']['startCursor'] | ||
); | ||
$this->assertEquals( | ||
$data['performance']['edges'][count($data['performance']['edges']) - 1]['cursor'], | ||
$data['performance']['pageInfo']['endCursor'] | ||
); | ||
} | ||
|
||
public function testPageInfoHasNextPage(): void | ||
{ | ||
$driver = new Driver($this->getEntityManager()); | ||
$schema = new Schema([ | ||
'query' => new ObjectType([ | ||
'name' => 'query', | ||
'fields' => [ | ||
'performance' => [ | ||
'type' => $driver->connection($driver->type(Performance::class)), | ||
'args' => [ | ||
'filter' => $driver->filter(Performance::class), | ||
], | ||
'resolve' => $driver->resolve(Performance::class), | ||
], | ||
], | ||
]), | ||
]); | ||
|
||
$query = '{ | ||
performance (filter: {_first:2}) { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
} | ||
edges { | ||
node { | ||
id | ||
} | ||
} | ||
} | ||
}'; | ||
$result = GraphQL::executeQuery($schema, $query); | ||
|
||
$data = $result->toArray()['data']; | ||
|
||
$this->assertTrue($data['performance']['pageInfo']['hasNextPage']); | ||
$this->assertFalse($data['performance']['pageInfo']['hasPreviousPage']); | ||
} | ||
|
||
public function testPageInfoHasPreviousPage(): void | ||
{ | ||
$driver = new Driver($this->getEntityManager()); | ||
$schema = new Schema([ | ||
'query' => new ObjectType([ | ||
'name' => 'query', | ||
'fields' => [ | ||
'performance' => [ | ||
'type' => $driver->connection($driver->type(Performance::class)), | ||
'args' => [ | ||
'filter' => $driver->filter(Performance::class), | ||
], | ||
'resolve' => $driver->resolve(Performance::class), | ||
], | ||
], | ||
]), | ||
]); | ||
|
||
$query = '{ | ||
performance (filter: {_last:2}) { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
} | ||
edges { | ||
node { | ||
id | ||
} | ||
} | ||
} | ||
}'; | ||
$result = GraphQL::executeQuery($schema, $query); | ||
|
||
$data = $result->toArray()['data']; | ||
|
||
$this->assertFalse($data['performance']['pageInfo']['hasNextPage']); | ||
$this->assertTrue($data['performance']['pageInfo']['hasPreviousPage']); | ||
} | ||
} |