From 2c8391fbe9db3f26e85797c470e574bc963d3456 Mon Sep 17 00:00:00 2001 From: Vincent Bouzeran Date: Mon, 29 Jan 2024 08:40:21 +0100 Subject: [PATCH 1/3] Fix profiler & update phpcs --- composer.json | 2 +- src/Controller/ProfilerController.php | 7 ++++++- src/Resources/config/profiler.yaml | 1 + tests/Controller/ProfilerControllerTest.php | 20 +++++++++++++++++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 7b031d2e0..498b3fc7e 100644 --- a/composer.json +++ b/composer.json @@ -91,7 +91,7 @@ "static-analysis": [ "phpstan analyse --ansi --memory-limit=1G" ], - "install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.17.0/php-cs-fixer.phar -O php-cs-fixer.phar", + "install-cs": "test -f php-cs-fixer.phar || wget https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/v3.48.0/php-cs-fixer.phar -O php-cs-fixer.phar", "fix-cs": [ "@install-cs", "@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi" diff --git a/src/Controller/ProfilerController.php b/src/Controller/ProfilerController.php index 592287ba1..a7ad44438 100644 --- a/src/Controller/ProfilerController.php +++ b/src/Controller/ProfilerController.php @@ -6,6 +6,7 @@ use GraphQL\Utils\SchemaPrinter; use Overblog\GraphQLBundle\Request\Executor as RequestExecutor; +use Overblog\GraphQLBundle\Resolver\TypeResolver; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -24,14 +25,16 @@ final class ProfilerController private ?Profiler $profiler; private ?Environment $twig; private string $endpointUrl; + private TypeResolver $typeResolver; private RequestExecutor $requestExecutor; private ?string $queryMatch; - public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch) + public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, TypeResolver $typeResolver, RequestExecutor $requestExecutor, ?string $queryMatch) { $this->profiler = $profiler; $this->twig = $twig; $this->endpointUrl = $router->generate('overblog_graphql_endpoint'); + $this->typeResolver = $typeResolver; $this->requestExecutor = $requestExecutor; $this->queryMatch = $queryMatch; } @@ -69,9 +72,11 @@ public function __invoke(Request $request, string $token): Response }, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, $limit, 'POST', null, null, null)); // @phpstan-ignore-line $schemas = []; + $this->typeResolver->setIgnoreUnresolvableException(true); foreach ($this->requestExecutor->getSchemasNames() as $schemaName) { $schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName)); } + $this->typeResolver->setIgnoreUnresolvableException(false); return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [ 'request' => $request, diff --git a/src/Resources/config/profiler.yaml b/src/Resources/config/profiler.yaml index 3d48b1641..eccbdb817 100644 --- a/src/Resources/config/profiler.yaml +++ b/src/Resources/config/profiler.yaml @@ -5,6 +5,7 @@ services: - "@?profiler" - "@?twig" - "@router" + - '@Overblog\GraphQLBundle\Resolver\TypeResolver' - '@Overblog\GraphQLBundle\Request\Executor' - "%overblog_graphql.profiler.query_match%" diff --git a/tests/Controller/ProfilerControllerTest.php b/tests/Controller/ProfilerControllerTest.php index 560b9ce21..948d9c1e7 100644 --- a/tests/Controller/ProfilerControllerTest.php +++ b/tests/Controller/ProfilerControllerTest.php @@ -7,7 +7,9 @@ use GraphQL\Type\Schema; use Overblog\GraphQLBundle\Controller\ProfilerController; use Overblog\GraphQLBundle\DataCollector\GraphQLCollector; +use Overblog\GraphQLBundle\Generator\TypeGenerator; use Overblog\GraphQLBundle\Request\Executor; +use Overblog\GraphQLBundle\Resolver\TypeResolver; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; @@ -45,6 +47,17 @@ protected function getMockExecutor(bool $expected = true): Executor return $executor; } + /** + * @return TypeGenerator&MockObject + */ + protected function getMockTypeResolver(int $expected = 2): TypeResolver + { + $typeGenerator = $this->getMockBuilder(TypeResolver::class)->disableOriginalConstructor()->onlyMethods(['setIgnoreUnresolvableException'])->getMock(); + $typeGenerator->expects($this->exactly($expected))->method('setIgnoreUnresolvableException'); + + return $typeGenerator; + } + /** * @return Profiler&MockObject */ @@ -58,7 +71,7 @@ protected function getMockProfiler(): Profiler public function testInvokeWithoutProfiler(): void { - $controller = new ProfilerController(null, null, $this->getMockRouter(), $this->getMockExecutor(false), null); + $controller = new ProfilerController(null, null, $this->getMockRouter(), $this->getMockTypeResolver(0), $this->getMockExecutor(false), null); $this->expectException(ServiceNotFoundException::class); $this->expectExceptionMessage('The profiler must be enabled.'); @@ -67,7 +80,7 @@ public function testInvokeWithoutProfiler(): void public function testInvokeWithoutTwig(): void { - $controller = new ProfilerController($this->getMockProfiler(), null, $this->getMockRouter(), $this->getMockExecutor(false), null); + $controller = new ProfilerController($this->getMockProfiler(), null, $this->getMockRouter(), $this->getMockTypeResolver(0), $this->getMockExecutor(false), null); $this->expectException(ServiceNotFoundException::class); $this->expectExceptionMessage('The GraphQL Profiler require twig'); @@ -79,10 +92,11 @@ public function testWithToken(): void $profilerMock = $this->getMockProfiler(); $executorMock = $this->getMockExecutor(); $routerMock = $this->getMockRouter(); + $typeGeneratorMock = $this->getMockTypeResolver(); /** @var Environment&MockObject $twigMock */ $twigMock = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->onlyMethods(['render'])->getMock(); - $controller = new ProfilerController($profilerMock, $twigMock, $routerMock, $executorMock, null); + $controller = new ProfilerController($profilerMock, $twigMock, $routerMock, $typeGeneratorMock, $executorMock, null); /** @var Profiler&MockObject $profilerMock */ $profilerMock->expects($this->once())->method('disable'); From ddb6c93b82071cc3e6e07006d93c4930153866ee Mon Sep 17 00:00:00 2001 From: Vincent Bouzeran Date: Mon, 29 Jan 2024 08:51:46 +0100 Subject: [PATCH 2/3] Update CI php version & fix static-analysis --- .github/workflows/ci.yml | 4 ++-- tests/Controller/ProfilerControllerTest.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d38a8a6f..51aed21ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: tools: flex - php-version: "8.1" + php-version: "8.2" coverage: "none" - name: "Install dependencies" @@ -116,7 +116,7 @@ jobs: - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.1" + php-version: "8.2" coverage: "none" - name: "Install dependencies" diff --git a/tests/Controller/ProfilerControllerTest.php b/tests/Controller/ProfilerControllerTest.php index 948d9c1e7..441f8a3cb 100644 --- a/tests/Controller/ProfilerControllerTest.php +++ b/tests/Controller/ProfilerControllerTest.php @@ -7,7 +7,6 @@ use GraphQL\Type\Schema; use Overblog\GraphQLBundle\Controller\ProfilerController; use Overblog\GraphQLBundle\DataCollector\GraphQLCollector; -use Overblog\GraphQLBundle\Generator\TypeGenerator; use Overblog\GraphQLBundle\Request\Executor; use Overblog\GraphQLBundle\Resolver\TypeResolver; use PHPUnit\Framework\MockObject\MockObject; @@ -48,7 +47,7 @@ protected function getMockExecutor(bool $expected = true): Executor } /** - * @return TypeGenerator&MockObject + * @return TypeResolver&MockObject */ protected function getMockTypeResolver(int $expected = 2): TypeResolver { From ca5ec9f13b789c65fc42b552f6f66fbd27ae936c Mon Sep 17 00:00:00 2001 From: Vincent Bouzeran Date: Mon, 29 Jan 2024 09:03:27 +0100 Subject: [PATCH 3/3] Fix CS --- .github/workflows/ci.yml | 2 +- src/Config/TypeDefinition.php | 1 + src/Relay/Connection/ConnectionInterface.php | 2 -- src/Relay/Connection/Output/PageInfo.php | 12 ------------ src/Relay/Connection/PageInfoInterface.php | 12 ------------ src/Resolver/TypeResolver.php | 2 -- src/Upload/Type/GraphQLUploadType.php | 3 --- src/Validator/InputValidator.php | 2 +- tests/Config/Parser/fixtures/graphql/schema.php | 6 +++--- 9 files changed, 6 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51aed21ab..fbcadec1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,7 +116,7 @@ jobs: - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.2" + php-version: "8.1" coverage: "none" - name: "Install dependencies" diff --git a/src/Config/TypeDefinition.php b/src/Config/TypeDefinition.php index a6f345b3b..65c72c548 100644 --- a/src/Config/TypeDefinition.php +++ b/src/Config/TypeDefinition.php @@ -81,6 +81,7 @@ protected function validationSection(int $level): ArrayNodeDefinition return $value; } } + // validation: [list of constraints] return ['constraints' => $value]; } diff --git a/src/Relay/Connection/ConnectionInterface.php b/src/Relay/Connection/ConnectionInterface.php index c9ed1b6d4..a0b1293ba 100644 --- a/src/Relay/Connection/ConnectionInterface.php +++ b/src/Relay/Connection/ConnectionInterface.php @@ -27,8 +27,6 @@ public function setEdges(iterable $edges): void; /** * Get the page info. - * - * @return PageInfoInterface */ public function getPageInfo(): ?PageInfoInterface; diff --git a/src/Relay/Connection/Output/PageInfo.php b/src/Relay/Connection/Output/PageInfo.php index 531db5c14..da9a5b999 100644 --- a/src/Relay/Connection/Output/PageInfo.php +++ b/src/Relay/Connection/Output/PageInfo.php @@ -23,9 +23,6 @@ public function __construct(string $startCursor = null, string $endCursor = null $this->hasNextPage = $hasNextPage; } - /** - * @return string - */ public function getStartCursor(): ?string { return $this->startCursor; @@ -36,9 +33,6 @@ public function setStartCursor(string $startCursor): void $this->startCursor = $startCursor; } - /** - * @return string - */ public function getEndCursor(): ?string { return $this->endCursor; @@ -49,9 +43,6 @@ public function setEndCursor(string $endCursor): void $this->endCursor = $endCursor; } - /** - * @return bool - */ public function getHasPreviousPage(): ?bool { return $this->hasPreviousPage; @@ -62,9 +53,6 @@ public function setHasPreviousPage(bool $hasPreviousPage): void $this->hasPreviousPage = $hasPreviousPage; } - /** - * @return bool - */ public function getHasNextPage(): ?bool { return $this->hasNextPage; diff --git a/src/Relay/Connection/PageInfoInterface.php b/src/Relay/Connection/PageInfoInterface.php index b735f48f4..a44aedb40 100644 --- a/src/Relay/Connection/PageInfoInterface.php +++ b/src/Relay/Connection/PageInfoInterface.php @@ -12,30 +12,18 @@ interface PageInfoInterface { - /** - * @return string - */ public function getStartCursor(): ?string; public function setStartCursor(string $startCursor): void; - /** - * @return string - */ public function getEndCursor(): ?string; public function setEndCursor(string $endCursor): void; - /** - * @return bool - */ public function getHasPreviousPage(): ?bool; public function setHasPreviousPage(bool $hasPreviousPage): void; - /** - * @return bool - */ public function getHasNextPage(): ?bool; public function setHasNextPage(bool $hasNextPage): void; diff --git a/src/Resolver/TypeResolver.php b/src/Resolver/TypeResolver.php index 26b9810a8..1793f9631 100644 --- a/src/Resolver/TypeResolver.php +++ b/src/Resolver/TypeResolver.php @@ -46,8 +46,6 @@ protected function onLoadSolution($solution): void /** * @param string $alias - * - * @return Type */ public function resolve($alias): ?Type { diff --git a/src/Upload/Type/GraphQLUploadType.php b/src/Upload/Type/GraphQLUploadType.php index 0b73079bc..7a4d30ec0 100644 --- a/src/Upload/Type/GraphQLUploadType.php +++ b/src/Upload/Type/GraphQLUploadType.php @@ -14,9 +14,6 @@ final class GraphQLUploadType extends ScalarType { - /** - * @param string $name - */ public function __construct(string $name = null) { parent::__construct([ diff --git a/src/Validator/InputValidator.php b/src/Validator/InputValidator.php index f8cb9bf6e..523f6dc96 100644 --- a/src/Validator/InputValidator.php +++ b/src/Validator/InputValidator.php @@ -63,7 +63,7 @@ public function __construct( /** * @throws ArgumentsValidationException */ - public function validate(string|array|null $groups = null, bool $throw = true): ?ConstraintViolationListInterface + public function validate(string|array $groups = null, bool $throw = true): ?ConstraintViolationListInterface { $rootNode = new ValidationNode( $this->info->parentType, diff --git a/tests/Config/Parser/fixtures/graphql/schema.php b/tests/Config/Parser/fixtures/graphql/schema.php index b56f77328..5c56e5f03 100644 --- a/tests/Config/Parser/fixtures/graphql/schema.php +++ b/tests/Config/Parser/fixtures/graphql/schema.php @@ -159,9 +159,9 @@ 'type' => 'custom-scalar', 'config' => [ 'description' => null, - 'serialize' => [\Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'], - 'parseValue' => [\Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'], - 'parseLiteral' => [\Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'], + 'serialize' => [Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'], + 'parseValue' => [Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'], + 'parseLiteral' => [Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'], ], ], ];