|
5 | 5 | namespace Overblog\GraphQLBundle\Config\Parser; |
6 | 6 |
|
7 | 7 | use Doctrine\Common\Annotations\AnnotationException; |
| 8 | +use Doctrine\Common\Collections\Collection; |
8 | 9 | use Doctrine\ORM\Mapping\Column; |
9 | 10 | use Doctrine\ORM\Mapping\JoinColumn; |
10 | 11 | use Doctrine\ORM\Mapping\ManyToMany; |
@@ -585,7 +586,7 @@ private static function getTypeFieldConfigurationFromReflector(GraphClass $graph |
585 | 586 | } |
586 | 587 | } else { |
587 | 588 | try { |
588 | | - $fieldConfiguration['type'] = self::guessType($graphClass, $annotations); |
| 589 | + $fieldConfiguration['type'] = self::guessType($graphClass, $reflector, self::VALID_OUTPUT_TYPES); |
589 | 590 | } catch (Exception $e) { |
590 | 591 | throw new InvalidArgumentException(sprintf('The attribute "type" on "@%s" defined on "%s" is required and cannot be auto-guessed : %s.', $fieldAnnotationName, $reflector->getName(), $e->getMessage())); |
591 | 592 | } |
@@ -639,22 +640,11 @@ private static function getGraphQLInputFieldsFromAnnotations(GraphClass $graphCl |
639 | 640 | if (isset($fieldAnnotation->type)) { |
640 | 641 | $fieldType = $fieldAnnotation->type; |
641 | 642 | } else { |
642 | | - if ($reflector instanceof ReflectionProperty) { |
643 | | - if ($reflector->hasType()) { |
644 | | - try { |
645 | | - // @phpstan-ignore-next-line |
646 | | - $fieldType = self::resolveGraphQLTypeFromReflectionType($reflector->getType(), self::VALID_INPUT_TYPES); |
647 | | - } catch (Exception $e) { |
648 | | - throw new InvalidArgumentException(sprintf('The attribute "type" on GraphQL annotation "@%s" is missing on property "%s" and cannot be auto-guessed from type hint "%s"', GQL\Field::class, $reflector->getName(), (string) $reflector->getType())); |
649 | | - } |
650 | | - } else { |
651 | | - try { |
652 | | - $fieldType = self::guessType($graphClass, $annotations); |
653 | | - } catch (Exception $e) { |
654 | | - throw new InvalidArgumentException(sprintf('The attribute "type" on GraphQL annotation "@%s" is missing on property "%s" and cannot be auto-guessed as there is no type hint or Doctrine annotation.', GQL\Field::class, $reflector->getName())); |
| 643 | + try { |
| 644 | + $fieldType = self::guessType($graphClass, $reflector, self::VALID_INPUT_TYPES); |
| 645 | + } catch (Exception $e) { |
| 646 | + throw new InvalidArgumentException(sprintf('The attribute "type" on GraphQL annotation "@%s" is missing on property "%s" and cannot be auto-guessed as there is no type hint or Doctrine annotation.', GQL\Field::class, $reflector->getName())); |
655 | 647 |
|
656 | | - } |
657 | | - } |
658 | 648 | } |
659 | 649 | } |
660 | 650 | $fieldConfiguration = []; |
@@ -864,8 +854,17 @@ private static function suffixName(string $name, string $suffix): string |
864 | 854 | * |
865 | 855 | * @throws RuntimeException |
866 | 856 | */ |
867 | | - private static function guessType(GraphClass $graphClass, array $annotations): string |
| 857 | + private static function guessType(GraphClass $graphClass, ReflectionProperty $reflector, array $filterGraphQLTypes = []): string |
868 | 858 | { |
| 859 | + if ($reflector->hasType()) { |
| 860 | + try { |
| 861 | + // @phpstan-ignore-next-line |
| 862 | + return self::resolveGraphQLTypeFromReflectionType($reflector->getType(), $filterGraphQLTypes); |
| 863 | + } catch (Exception $e) { |
| 864 | + } |
| 865 | + } |
| 866 | + |
| 867 | + $annotations = $graphClass->getAnnotations($reflector); |
869 | 868 | $columnAnnotation = self::getFirstAnnotationMatching($annotations, Column::class); |
870 | 869 | if (null !== $columnAnnotation) { |
871 | 870 | $type = self::resolveTypeFromDoctrineType($columnAnnotation->type); |
|
0 commit comments