Skip to content

Commit d13f715

Browse files
committed
First try property type before quessing this from annotations
Now with tests
1 parent 9ce6b96 commit d13f715

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/Config/Parser/AnnotationParser.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,14 @@ private static function getGraphQLInputFieldsFromAnnotations(GraphClass $graphCl
636636
}
637637

638638
$fieldName = $reflector->getName();
639-
$fieldType = $fieldAnnotation->type ?? self::guessType($graphClass, $annotations);
639+
$fieldType = $fieldAnnotation->type ?? null;
640+
if (!$fieldType) {
641+
if ($reflector instanceof ReflectionProperty && $reflector->hasType()) {
642+
$fieldType = self::resolveGraphQLTypeFromReflectionType($reflector->getType(), self::VALID_INPUT_TYPES);
643+
} else {
644+
$fieldType = self::guessType($graphClass, $annotations);
645+
}
646+
}
640647
$fieldConfiguration = [];
641648
if ($fieldType) {
642649
// Resolve a PHP class from a GraphQL type

tests/Config/Parser/AnnotationParserTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ public function testInput(): void
188188
'fields' => [
189189
'name' => ['type' => 'String!'],
190190
'population' => ['type' => 'Int!'],
191+
'description' => ['type' => 'String!'],
192+
'diameter' => ['type' => 'Int'],
191193
],
192194
]);
193195
}

tests/Config/Parser/fixtures/annotations/Input/Planet.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Overblog\GraphQLBundle\Tests\Config\Parser\fixtures\annotations\Input;
66

7+
use Doctrine\ORM\Mapping as ORM;
78
use Overblog\GraphQLBundle\Annotation as GQL;
89

910
/**
@@ -21,4 +22,17 @@ class Planet
2122
* @GQL\Field(type="Int!")
2223
*/
2324
protected string $population;
25+
26+
/**
27+
* @GQL\Field
28+
*/
29+
protected string $description;
30+
31+
/**
32+
* @GQL\Field
33+
* @ORM\Column(type="integer", nullable=true)
34+
*/
35+
protected $diameter;
36+
37+
protected $dummy;
2438
}

0 commit comments

Comments
 (0)