Skip to content

Add private property annotations from inherited classes #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Config/Parser/AnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,15 @@ private static function extractClassAnnotations(string $className): array
$classAnnotations = $annotationReader->getClassAnnotations($reflectionEntity);

$properties = [];
foreach ($reflectionEntity->getProperties() as $property) {
$properties[$property->getName()] = ['property' => $property, 'annotations' => $annotationReader->getPropertyAnnotations($property)];
}
$reflectionClass = new \ReflectionClass($className);
do {
foreach ($reflectionClass->getProperties() as $property) {
if (isset($properties[$property->getName()])) {
continue;
}
$properties[$property->getName()] = ['property' => $property, 'annotations' => $annotationReader->getPropertyAnnotations($property)];
}
} while ($reflectionClass = $reflectionClass->getParentClass());

$methods = [];
foreach ($reflectionEntity->getMethods() as $method) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Config/Parser/AnnotationParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ public function testTypes(): void
],
'builders' => [['builder' => 'MyFieldsBuilder', 'builderConfig' => ['param1' => 'val1']]],
]);

// Test a type extending another type
$this->expect('Cat', 'object', [
'description' => 'The Cat type',
'fields' => [
'name' => ['type' => 'String!', 'description' => 'The name of the animal'],
'lives' => ['type' => 'Int!'],
],
]);
}

public function testInput(): void
Expand Down
25 changes: 25 additions & 0 deletions tests/Config/Parser/fixtures/annotations/Type/Animal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Overblog\GraphQLBundle\Tests\Config\Parser\fixtures\annotations\Type;

use Overblog\GraphQLBundle\Annotation as GQL;

/**
* @GQL\Type()
* @GQL\Description("The character interface")
*/
abstract class Animal
{
/**
* @GQL\Field(type="String!")
* @GQL\Description("The name of the animal")
*/
private $name;

/**
* @GQL\Field(type="String!")
*/
private $lives;
}
19 changes: 19 additions & 0 deletions tests/Config/Parser/fixtures/annotations/Type/Cat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Overblog\GraphQLBundle\Tests\Config\Parser\fixtures\annotations\Type;

use Overblog\GraphQLBundle\Annotation as GQL;

/**
* @GQL\Type()
* @GQL\Description("The Cat type")
*/
class Cat extends Animal
{
/**
* @GQL\Field(type="Int!")
*/
protected $lives;
}