From ab6796bcb5fb69990df0c3b874f0440202df5a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 8 Dec 2020 12:17:37 +0100 Subject: [PATCH] Fixing detection of PHP 8 attributes in compiler pass --- .../GraphqliteCompilerPass.php | 2 +- .../Controller/TestPhp8GraphqlController.php | 30 +++++++++++++++++++ Tests/FunctionalTest.php | 21 +++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Tests/Fixtures/Controller/TestPhp8GraphqlController.php diff --git a/DependencyInjection/GraphqliteCompilerPass.php b/DependencyInjection/GraphqliteCompilerPass.php index 2e7ebdd..e661e5e 100644 --- a/DependencyInjection/GraphqliteCompilerPass.php +++ b/DependencyInjection/GraphqliteCompilerPass.php @@ -336,7 +336,7 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio $services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController) { $services = []; foreach ($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { - $field = $reader->getRequestAnnotation($method, AbstractRequest::class); + $field = $reader->getRequestAnnotation($method, Field::class) ?? $reader->getRequestAnnotation($method, Query::class) ?? $reader->getRequestAnnotation($method, Mutation::class); if ($field !== null) { if ($isController) { $services[$refClass->getName()] = $refClass->getName(); diff --git a/Tests/Fixtures/Controller/TestPhp8GraphqlController.php b/Tests/Fixtures/Controller/TestPhp8GraphqlController.php new file mode 100644 index 0000000..a8cc36b --- /dev/null +++ b/Tests/Fixtures/Controller/TestPhp8GraphqlController.php @@ -0,0 +1,30 @@ +get('security.token_storage')->setToken($token); } + + public function testPhp8Attributes(): void + { + $kernel = new GraphqliteTestingKernel(); + $kernel->boot(); + + $request = Request::create('/graphql', 'GET', ['query' => ' + { + testPhp8(foo: "bar") + }']); + + $response = $kernel->handle($request); + + $result = json_decode($response->getContent(), true); + + $this->assertSame([ + 'data' => [ + 'testPhp8' => 'echo bar' + ] + ], $result); + } }