|
4 | 4 | namespace TheCodingMachine\GraphQLite; |
5 | 5 |
|
6 | 6 | use function array_merge; |
| 7 | +use function get_parent_class; |
7 | 8 | use GraphQL\Type\Definition\InputType; |
8 | 9 | use GraphQL\Type\Definition\ListOfType; |
9 | 10 | use GraphQL\Type\Definition\NonNull; |
|
15 | 16 | use phpDocumentor\Reflection\Types\Self_; |
16 | 17 | use Psr\Http\Message\UploadedFileInterface; |
17 | 18 | use ReflectionMethod; |
| 19 | +use TheCodingMachine\GraphQLite\Annotations\Field; |
18 | 20 | use TheCodingMachine\GraphQLite\Annotations\SourceFieldInterface; |
19 | 21 | use TheCodingMachine\GraphQLite\Hydrators\HydratorInterface; |
20 | 22 | use TheCodingMachine\GraphQLite\Mappers\CannotMapTypeExceptionInterface; |
@@ -222,7 +224,21 @@ private function getFieldsByAnnotations($controller, string $annotationName, boo |
222 | 224 | $oldDeclaringClass = null; |
223 | 225 | $context = null; |
224 | 226 |
|
| 227 | + $closestMatchingTypeClass = null; |
| 228 | + if ($annotationName === Field::class) { |
| 229 | + $parent = get_parent_class($refClass->getName()); |
| 230 | + if ($parent !== null) { |
| 231 | + $closestMatchingTypeClass = $this->typeMapper->findClosestMatchingParent($parent); |
| 232 | + } |
| 233 | + } |
| 234 | + |
225 | 235 | foreach ($refClass->getMethods() as $refMethod) { |
| 236 | + if ($closestMatchingTypeClass !== null && $closestMatchingTypeClass === $refMethod->getDeclaringClass()->getName()) { |
| 237 | + // Optimisation: no need to fetch annotations from parent classes that are ALREADY GraphQL types. |
| 238 | + // We will merge the fields anyway. |
| 239 | + break; |
| 240 | + } |
| 241 | + |
226 | 242 | // First, let's check the "Query" or "Mutation" or "Field" annotation |
227 | 243 | $queryAnnotation = $this->annotationReader->getRequestAnnotation($refMethod, $annotationName); |
228 | 244 |
|
|
0 commit comments