Skip to content

Commit 5811da0

Browse files
authored
Handle explicit null for page argument in paginated queries
1 parent 7956fb9 commit 5811da0

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co
99

1010
## Unreleased
1111

12+
## v6.64.1
13+
14+
### Fixed
15+
16+
- Handle explicit `null` for `page` argument in paginated queries https://github.com/nuwave/lighthouse/pull/2735
17+
1218
## v6.64.0
1319

1420
### Added

src/Pagination/PaginationArgs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function extractArgs(array $args, ResolveInfo $resolveInfo, Pagina
3636
Cursor::decode($args),
3737
)
3838
// Handles cases "paginate" and "simple", which both take the same args.
39-
: Arr::get($args, 'page', 1);
39+
: Arr::get($args, 'page') ?? 1;
4040

4141
if ($first < 0) {
4242
throw new Error(self::requestedLessThanZeroItems($first));

tests/Integration/Pagination/PaginateDirectiveDBTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,4 +1010,45 @@ public function testPaginateWithCacheDirective(): void
10101010
}
10111011
');
10121012
}
1013+
1014+
public function testSimplePaginationWithNullPageUsesDefaultPage(): void
1015+
{
1016+
factory(User::class, 3)->create();
1017+
1018+
$this->schema = /** @lang GraphQL */ '
1019+
type User {
1020+
id: ID!
1021+
name: String!
1022+
}
1023+
1024+
type Query {
1025+
users: [User!] @paginate(type: SIMPLE)
1026+
}
1027+
';
1028+
1029+
$this->graphQL(/** @lang GraphQL */ '
1030+
query ($page: Int) {
1031+
users(first: 2, page: $page) {
1032+
paginatorInfo {
1033+
currentPage
1034+
count
1035+
}
1036+
data {
1037+
id
1038+
}
1039+
}
1040+
}
1041+
', [
1042+
'page' => null,
1043+
])->assertJson([
1044+
'data' => [
1045+
'users' => [
1046+
'paginatorInfo' => [
1047+
'currentPage' => 1,
1048+
'count' => 2,
1049+
],
1050+
],
1051+
],
1052+
])->assertJsonCount(2, 'data.users.data');
1053+
}
10131054
}

0 commit comments

Comments
 (0)