From bf31959e6c34127091ac46714497b0bad2ee5b30 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 5 Mar 2024 15:48:47 -0500 Subject: [PATCH 1/8] relax typehint --- src/Support/PaginationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/PaginationType.php b/src/Support/PaginationType.php index ff9cc710..795a6102 100644 --- a/src/Support/PaginationType.php +++ b/src/Support/PaginationType.php @@ -29,7 +29,7 @@ public function __construct(string $typeName, string $customName = null) parent::__construct($config); } - protected function getPaginationFields(ObjectType $underlyingType): array + protected function getPaginationFields(GraphQLType $underlyingType): array { return [ 'data' => [ From 7f80adddb0e0a01bcf06bc338ca266d079b297ca Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 5 Mar 2024 16:00:40 -0500 Subject: [PATCH 2/8] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447b7414..428248fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ CHANGELOG [Next release](https://github.com/rebing/graphql-laravel/compare/9.4.0...master) +### Fixed +- Relax PaginationType getPaginationFields typehint [\#1132 / jasonvarga](https://github.com/rebing/graphql-laravel/pull/1132) + 2024-03-04, 9.4.0 ----------------- From 392c17d4010a6b8754a04f8fb9796887cb7b14e1 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 6 Mar 2024 10:36:51 -0500 Subject: [PATCH 3/8] Add test --- .../PrimaryKeyTests/ModelInterfaceType.php | 31 ++++++++++ .../PrimaryKeyTests/PaginationTest.php | 57 +++++++++++++++++++ .../SelectFields/PrimaryKeyTests/PostType.php | 7 +++ .../PrimaryKeyInterfacePaginationQuery.php | 25 ++++++++ 4 files changed, 120 insertions(+) create mode 100644 tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php create mode 100644 tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php diff --git a/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php b/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php new file mode 100644 index 00000000..c4ce7fa6 --- /dev/null +++ b/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php @@ -0,0 +1,31 @@ + 'ModelInterface', + ]; + + public function fields(): array + { + return [ + 'id' => [ + 'type' => Type::nonNull(Type::ID()), + ], + ]; + } + + public function resolveType($root) + { + return GraphQL::type('Post'); + } +} diff --git a/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php b/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php index 82403bc6..a08eff82 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php @@ -3,6 +3,8 @@ declare(strict_types = 1); namespace Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests; +use Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests\ModelInterfaceType; +use Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests\PrimaryKeyInterfacePaginationQuery; use Rebing\GraphQL\Tests\Support\Models\Comment; use Rebing\GraphQL\Tests\Support\Models\Post; use Rebing\GraphQL\Tests\Support\Traits\SqlAssertionTrait; @@ -20,10 +22,12 @@ protected function getEnvironmentSetUp($app): void 'query' => [ PrimaryKeyQuery::class, PrimaryKeyPaginationQuery::class, + PrimaryKeyInterfacePaginationQuery::class, ], ]); $app['config']->set('graphql.types', [ + ModelInterfaceType::class, CommentType::class, PostType::class, ]); @@ -105,4 +109,57 @@ public function testPagination(): void ]; self::assertEquals($expectedResult, $result); } + + public function testInterfacePagination(): void + { + Post::factory(2)->create(); + + $query = <<<'GRAQPHQL' +{ + primaryKeyInterfacePaginationQuery { + current_page + data { + id + } + from + has_more_pages + last_page + per_page + to + total + } +} +GRAQPHQL; + + $this->sqlCounterReset(); + + $result = $this->httpGraphql($query); + +// $this->assertSqlQueries( +// <<<'SQL' +//select count(*) as aggregate from "posts"; +//select "posts"."id" from "posts" limit 1 offset 0; +//SQL +// ); + + $expectedResult = [ + 'data' => [ + 'primaryKeyInterfacePaginationQuery' => [ + 'current_page' => 1, + 'data' => [ + [ + 'id' => '1', + ], + ], + 'from' => 1, + 'has_more_pages' => true, + 'last_page' => 2, + 'per_page' => 1, + 'to' => 1, + 'total' => 2, + ], + ], + ]; + self::assertEquals($expectedResult, $result); + } } diff --git a/tests/Database/SelectFields/PrimaryKeyTests/PostType.php b/tests/Database/SelectFields/PrimaryKeyTests/PostType.php index e5d1588e..7599ec8b 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/PostType.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/PostType.php @@ -32,4 +32,11 @@ public function fields(): array ], ]; } + + public function interfaces(): array + { + return [ + GraphQL::type('ModelInterface'), + ]; + } } diff --git a/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php b/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php new file mode 100644 index 00000000..f9ce47c8 --- /dev/null +++ b/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php @@ -0,0 +1,25 @@ + 'primaryKeyInterfacePaginationQuery', + ]; + + public function type(): Type + { + return GraphQL::paginate('ModelInterface'); + } +} From db53a3ca6eefd7ade3557a9419fed11a2727c92b Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 6 Mar 2024 11:05:52 -0500 Subject: [PATCH 4/8] fix-style --- .../PrimaryKeyTests/ModelInterfaceType.php | 2 -- .../PrimaryKeyTests/PaginationTest.php | 14 ++++++-------- .../PrimaryKeyInterfacePaginationQuery.php | 6 ------ 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php b/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php index c4ce7fa6..2fb056d2 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php @@ -6,8 +6,6 @@ use GraphQL\Type\Definition\Type; use Rebing\GraphQL\Support\Facades\GraphQL; use Rebing\GraphQL\Support\InterfaceType; -use Rebing\GraphQL\Support\Type as GraphQLType; -use Rebing\GraphQL\Tests\Support\Models\Post; class ModelInterfaceType extends InterfaceType { diff --git a/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php b/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php index a08eff82..0cfeb6f4 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php @@ -3,8 +3,6 @@ declare(strict_types = 1); namespace Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests; -use Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests\ModelInterfaceType; -use Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests\PrimaryKeyInterfacePaginationQuery; use Rebing\GraphQL\Tests\Support\Models\Comment; use Rebing\GraphQL\Tests\Support\Models\Post; use Rebing\GraphQL\Tests\Support\Traits\SqlAssertionTrait; @@ -135,12 +133,12 @@ public function testInterfacePagination(): void $result = $this->httpGraphql($query); -// $this->assertSqlQueries( -// <<<'SQL' -//select count(*) as aggregate from "posts"; -//select "posts"."id" from "posts" limit 1 offset 0; -//SQL -// ); + // $this->assertSqlQueries( + // <<<'SQL' + //select count(*) as aggregate from "posts"; + //select "posts"."id" from "posts" limit 1 offset 0; + //SQL + // ); $expectedResult = [ 'data' => [ diff --git a/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php b/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php index f9ce47c8..f7318280 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/PrimaryKeyInterfacePaginationQuery.php @@ -3,14 +3,8 @@ declare(strict_types = 1); namespace Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests; -use Closure; -use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type; use Rebing\GraphQL\Support\Facades\GraphQL; -use Rebing\GraphQL\Support\Query; -use Rebing\GraphQL\Support\SelectFields; -use Rebing\GraphQL\Tests\Database\SelectFields\PrimaryKeyTests\PrimaryKeyPaginationQuery; -use Rebing\GraphQL\Tests\Support\Models\Post; class PrimaryKeyInterfacePaginationQuery extends PrimaryKeyPaginationQuery { From cf55eab26a161fc8968cfa36d8553338442fc488 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Wed, 6 Mar 2024 20:12:17 +0100 Subject: [PATCH 5/8] pagination: relax underlying field also for SimplePagination --- CHANGELOG.md | 2 +- src/Support/SimplePaginationType.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 428248fa..e98cf448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG [Next release](https://github.com/rebing/graphql-laravel/compare/9.4.0...master) ### Fixed -- Relax PaginationType getPaginationFields typehint [\#1132 / jasonvarga](https://github.com/rebing/graphql-laravel/pull/1132) +- Relax PaginationType/SimplePaginationType getPaginationFields typehint [\#1132 / jasonvarga](https://github.com/rebing/graphql-laravel/pull/1132) 2024-03-04, 9.4.0 ----------------- diff --git a/src/Support/SimplePaginationType.php b/src/Support/SimplePaginationType.php index 9ad778ba..6925e471 100644 --- a/src/Support/SimplePaginationType.php +++ b/src/Support/SimplePaginationType.php @@ -32,7 +32,7 @@ public function __construct(string $typeName, string $customName = null) /** * @return array> */ - protected function getPaginationFields(ObjectType $underlyingType): array + protected function getPaginationFields(GraphQLType $underlyingType): array { return [ 'data' => [ From 02ff3916e18eca91ac349b890adf254225a31536 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Wed, 6 Mar 2024 20:19:47 +0100 Subject: [PATCH 6/8] phpstan: fix errors --- phpstan-baseline.neon | 4 ++-- .../SelectFields/PrimaryKeyTests/ModelInterfaceType.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f3a412c3..b5b65637 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -226,7 +226,7 @@ parameters: path: src/Support/PaginationType.php - - message: "#^Parameter \\#1 \\$underlyingType of method Rebing\\\\GraphQL\\\\Support\\\\PaginationType\\:\\:getPaginationFields\\(\\) expects GraphQL\\\\Type\\\\Definition\\\\ObjectType, GraphQL\\\\Type\\\\Definition\\\\Type given\\.$#" + message: "#^Parameter \\#1 \\$type of static method GraphQL\\\\Type\\\\Definition\\\\Type\\:\\:nonNull\\(\\) expects \\(callable\\(\\)\\: \\(GraphQL\\\\Type\\\\Definition\\\\NullableType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\)\\|\\(GraphQL\\\\Type\\\\Definition\\\\NullableType&GraphQL\\\\Type\\\\Definition\\\\Type\\), GraphQL\\\\Type\\\\Definition\\\\Type given\\.$#" count: 1 path: src/Support/PaginationType.php @@ -366,7 +366,7 @@ parameters: path: src/Support/SelectFields.php - - message: "#^Parameter \\#1 \\$underlyingType of method Rebing\\\\GraphQL\\\\Support\\\\SimplePaginationType\\:\\:getPaginationFields\\(\\) expects GraphQL\\\\Type\\\\Definition\\\\ObjectType, GraphQL\\\\Type\\\\Definition\\\\Type given\\.$#" + message: "#^Parameter \\#1 \\$type of static method GraphQL\\\\Type\\\\Definition\\\\Type\\:\\:nonNull\\(\\) expects \\(callable\\(\\)\\: \\(GraphQL\\\\Type\\\\Definition\\\\NullableType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\)\\|\\(GraphQL\\\\Type\\\\Definition\\\\NullableType&GraphQL\\\\Type\\\\Definition\\\\Type\\), GraphQL\\\\Type\\\\Definition\\\\Type given\\.$#" count: 1 path: src/Support/SimplePaginationType.php diff --git a/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php b/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php index 2fb056d2..bc954c99 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/ModelInterfaceType.php @@ -6,6 +6,7 @@ use GraphQL\Type\Definition\Type; use Rebing\GraphQL\Support\Facades\GraphQL; use Rebing\GraphQL\Support\InterfaceType; +use Rebing\GraphQL\Tests\Support\Models\Post; class ModelInterfaceType extends InterfaceType { @@ -22,7 +23,7 @@ public function fields(): array ]; } - public function resolveType($root) + public function resolveType(Post $root): Type { return GraphQL::type('Post'); } From a901c3adf5236ffd7f0b45f4200935fad0580dd7 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Wed, 6 Mar 2024 20:20:11 +0100 Subject: [PATCH 7/8] tests: enabled SQL snapshot --- .../SelectFields/PrimaryKeyTests/PaginationTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php b/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php index 0cfeb6f4..e144f96e 100644 --- a/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php +++ b/tests/Database/SelectFields/PrimaryKeyTests/PaginationTest.php @@ -133,12 +133,12 @@ public function testInterfacePagination(): void $result = $this->httpGraphql($query); - // $this->assertSqlQueries( - // <<<'SQL' - //select count(*) as aggregate from "posts"; - //select "posts"."id" from "posts" limit 1 offset 0; - //SQL - // ); + $this->assertSqlQueries( + <<<'SQL' + select count(*) as aggregate from "posts"; + select * from "posts" limit 1 offset 0; + SQL + ); $expectedResult = [ 'data' => [ From 019c4d07cba867a14a7a20c2d835457daa775751 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Wed, 6 Mar 2024 20:24:37 +0100 Subject: [PATCH 8/8] Prepare 9.5.0 release --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e98cf448..12b76145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ CHANGELOG ========= -[Next release](https://github.com/rebing/graphql-laravel/compare/9.4.0...master) +[Next release](https://github.com/rebing/graphql-laravel/compare/9.5.0...master) -### Fixed +2024-03-06, 9.5.0 +----------------- + +### Changed - Relax PaginationType/SimplePaginationType getPaginationFields typehint [\#1132 / jasonvarga](https://github.com/rebing/graphql-laravel/pull/1132) 2024-03-04, 9.4.0