3232use TheCodingMachine \GraphQLite \Mappers \Root \RootTypeMapperInterface ;
3333use TheCodingMachine \GraphQLite \Middlewares \FieldHandlerInterface ;
3434use TheCodingMachine \GraphQLite \Middlewares \FieldMiddlewareInterface ;
35+ use TheCodingMachine \GraphQLite \Middlewares \MissingMagicGetException ;
3536use TheCodingMachine \GraphQLite \Parameters \InputTypeProperty ;
3637use TheCodingMachine \GraphQLite \Parameters \ParameterInterface ;
3738use TheCodingMachine \GraphQLite \Reflection \CachedDocBlockFactory ;
@@ -618,8 +619,9 @@ private function getQueryFieldsFromSourceFields(array $sourceFields, ReflectionC
618619 } else {
619620 $ phpTypeStr = $ sourceField ->getPhpType ();
620621 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 );
623625 }
624626 }
625627
@@ -644,6 +646,32 @@ public function handle(QueryFieldDescriptor $fieldDescriptor): ?FieldDefinition
644646 return $ queryList ;
645647 }
646648
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+
647675 /**
648676 * @param ReflectionClass<object> $refClass
649677 *
0 commit comments