32
32
use TheCodingMachine \GraphQLite \Mappers \Root \RootTypeMapperInterface ;
33
33
use TheCodingMachine \GraphQLite \Middlewares \FieldHandlerInterface ;
34
34
use TheCodingMachine \GraphQLite \Middlewares \FieldMiddlewareInterface ;
35
+ use TheCodingMachine \GraphQLite \Middlewares \MissingMagicGetException ;
35
36
use TheCodingMachine \GraphQLite \Parameters \InputTypeProperty ;
36
37
use TheCodingMachine \GraphQLite \Parameters \ParameterInterface ;
37
38
use TheCodingMachine \GraphQLite \Reflection \CachedDocBlockFactory ;
@@ -618,8 +619,9 @@ private function getQueryFieldsFromSourceFields(array $sourceFields, ReflectionC
618
619
} else {
619
620
$ phpTypeStr = $ sourceField ->getPhpType ();
620
621
Assert::notNull ($ phpTypeStr );
621
- $ refMethod = $ refClass ->getMethod ('__get ' );
622
- $ type = $ this ->resolvePhpType ($ phpTypeStr , $ refClass , $ refMethod );
622
+ $ magicGefRefMethod = $ this ->getMagicGetMethodFromSourceClassOrProxy ($ refClass );
623
+
624
+ $ type = $ this ->resolvePhpType ($ phpTypeStr , $ refClass , $ magicGefRefMethod );
623
625
}
624
626
}
625
627
@@ -644,6 +646,32 @@ public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition
644
646
return $ queryList ;
645
647
}
646
648
649
+ /**
650
+ * @throws ReflectionException
651
+ * @throws MissingAnnotationException
652
+ * @throws MissingMagicGetException
653
+ */
654
+ private function getMagicGetMethodFromSourceClassOrProxy (ReflectionClass $ proxyRefClass ): ReflectionMethod
655
+ {
656
+ $ magicGet = '__get ' ;
657
+ if ($ proxyRefClass ->hasMethod ($ magicGet )) {
658
+ return $ proxyRefClass ->getMethod ($ magicGet );
659
+ }
660
+
661
+ $ typeField = $ this ->annotationReader ->getTypeAnnotation ($ proxyRefClass );
662
+ if ($ typeField === null ) {
663
+ throw MissingAnnotationException::missingTypeException ($ proxyRefClass ->getName ());
664
+ }
665
+
666
+ $ sourceClassName = $ typeField ->getClass ();
667
+ $ sourceRefClass = new ReflectionClass ($ sourceClassName );
668
+ if (! $ sourceRefClass ->hasMethod ($ magicGet )) {
669
+ throw MissingMagicGetException::cannotFindMagicGet ($ sourceClassName );
670
+ }
671
+
672
+ return $ sourceRefClass ->getMethod ($ magicGet );
673
+ }
674
+
647
675
/**
648
676
* @param ReflectionClass<object> $refClass
649
677
*
0 commit comments