Skip to content

Commit ab6796b

Browse files
committed
Fixing detection of PHP 8 attributes in compiler pass
1 parent c4951c3 commit ab6796b

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

DependencyInjection/GraphqliteCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio
336336
$services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController) {
337337
$services = [];
338338
foreach ($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
339-
$field = $reader->getRequestAnnotation($method, AbstractRequest::class);
339+
$field = $reader->getRequestAnnotation($method, Field::class) ?? $reader->getRequestAnnotation($method, Query::class) ?? $reader->getRequestAnnotation($method, Mutation::class);
340340
if ($field !== null) {
341341
if ($isController) {
342342
$services[$refClass->getName()] = $refClass->getName();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Controller;
5+
6+
7+
use GraphQL\Error\Error;
8+
use Porpaginas\Arrays\ArrayResult;
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\Validator\Constraints as Assert;
11+
use TheCodingMachine\GraphQLite\Annotations\FailWith;
12+
use TheCodingMachine\GraphQLite\Annotations\Logged;
13+
use TheCodingMachine\GraphQLite\Annotations\Right;
14+
use TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Entities\Contact;
15+
use TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Entities\Product;
16+
use TheCodingMachine\GraphQLite\Annotations\Mutation;
17+
use TheCodingMachine\GraphQLite\Annotations\Query;
18+
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
19+
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;
20+
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
21+
use TheCodingMachine\Graphqlite\Validator\Fixtures\Types\User;
22+
23+
class TestPhp8GraphqlController
24+
{
25+
#[Query]
26+
public function testPhp8(string $foo): string
27+
{
28+
return 'echo ' .$foo;
29+
}
30+
}

Tests/FunctionalTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,25 @@ private function logIn(ContainerInterface $container)
533533
$token = new UsernamePasswordToken($user, '', 'provider', ['ROLE_USER']);
534534
$container->get('security.token_storage')->setToken($token);
535535
}
536+
537+
public function testPhp8Attributes(): void
538+
{
539+
$kernel = new GraphqliteTestingKernel();
540+
$kernel->boot();
541+
542+
$request = Request::create('/graphql', 'GET', ['query' => '
543+
{
544+
testPhp8(foo: "bar")
545+
}']);
546+
547+
$response = $kernel->handle($request);
548+
549+
$result = json_decode($response->getContent(), true);
550+
551+
$this->assertSame([
552+
'data' => [
553+
'testPhp8' => 'echo bar'
554+
]
555+
], $result);
556+
}
536557
}

0 commit comments

Comments
 (0)