Skip to content

Commit

Permalink
Merge pull request #82 from moufmouf/fix_php8_attribute_detection
Browse files Browse the repository at this point in the history
Fixing detection of PHP 8 attributes in compiler pass
  • Loading branch information
moufmouf authored Dec 8, 2020
2 parents c4951c3 + ab6796b commit a14b9a0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DependencyInjection/GraphqliteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 30 additions & 0 deletions Tests/Fixtures/Controller/TestPhp8GraphqlController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php


namespace TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Controller;


use GraphQL\Error\Error;
use Porpaginas\Arrays\ArrayResult;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints as Assert;
use TheCodingMachine\GraphQLite\Annotations\FailWith;
use TheCodingMachine\GraphQLite\Annotations\Logged;
use TheCodingMachine\GraphQLite\Annotations\Right;
use TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Entities\Contact;
use TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Entities\Product;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;
use TheCodingMachine\Graphqlite\Validator\Annotations\Assertion;
use TheCodingMachine\Graphqlite\Validator\Fixtures\Types\User;

class TestPhp8GraphqlController
{
#[Query]
public function testPhp8(string $foo): string
{
return 'echo ' .$foo;
}
}
21 changes: 21 additions & 0 deletions Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,25 @@ private function logIn(ContainerInterface $container)
$token = new UsernamePasswordToken($user, '', 'provider', ['ROLE_USER']);
$container->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);
}
}

0 comments on commit a14b9a0

Please sign in to comment.