@@ -337,13 +337,16 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio
337337 $ services = $ this ->getCodeCache ()->get ($ refClass , function () use ($ refClass , $ reader , $ container , $ isController ): array {
338338 $ services = [];
339339 foreach ($ refClass ->getMethods (ReflectionMethod::IS_PUBLIC ) as $ method ) {
340- $ field = $ reader -> getRequestAnnotation ( $ method , Field::class) ?? $ reader-> getRequestAnnotation ( $ method , Query::class) ?? $ reader -> getRequestAnnotation ( $ method, Mutation::class );
341- if ($ field !== null ) {
340+ $ resolveResult = $ this -> resolveFieldGraphqlElement ( $ reader, $ method );
341+ if ($ resolveResult [ ' exists ' ] ) {
342342 if ($ isController ) {
343343 $ services [$ refClass ->getName ()] = $ refClass ->getName ();
344344 }
345+
345346 $ services += $ this ->getListOfInjectedServices ($ method , $ container );
346- if ($ field instanceof Field && $ field ->getPrefetchMethod () !== null ) {
347+
348+ $ field = $ resolveResult ['field ' ];
349+ if (null !== $ field && $ field ->getPrefetchMethod () !== null ) {
347350 $ services += $ this ->getListOfInjectedServices ($ refClass ->getMethod ($ field ->getPrefetchMethod ()), $ container );
348351 }
349352 }
@@ -467,4 +470,29 @@ private function getClassList(string $namespace): Generator
467470 }
468471 }
469472
473+ /**
474+ * @return array{exists: bool, field: Field|null}
475+ */
476+ private function resolveFieldGraphqlElement (AnnotationReader $ reader , ReflectionMethod $ method ): array
477+ {
478+ // backward compatibility with graphqlite v8.1
479+ // @phpstan-ignore function.alreadyNarrowedType
480+ if (false === \method_exists ($ reader , 'getGraphQLElementAnnotation ' )) {
481+ // graphqlite versions in this BC branch expose getRequestAnnotation instead.
482+ // @phpstan-ignore method.notFound
483+ $ element = $ reader ->getRequestAnnotation ($ method , Field::class)
484+ // @phpstan-ignore method.notFound
485+ ?? $ reader ->getRequestAnnotation ($ method , Query::class)
486+ // @phpstan-ignore method.notFound
487+ ?? $ reader ->getRequestAnnotation ($ method , Mutation::class);
488+
489+ return ['exists ' => null !== $ element , 'field ' => ($ element instanceof Field ? $ element : null )];
490+ }
491+
492+ $ element = $ reader ->getGraphQLElementAnnotation ($ method , Field::class)
493+ ?? $ reader ->getGraphQLElementAnnotation ($ method , Query::class)
494+ ?? $ reader ->getGraphQLElementAnnotation ($ method , Mutation::class);
495+
496+ return ['exists ' => null !== $ element , 'field ' => ($ element instanceof Field ? $ element : null )];
497+ }
470498}
0 commit comments