1717use ApiPlatform \Metadata \GraphQl \Mutation ;
1818use ApiPlatform \Metadata \GraphQl \Operation ;
1919use ApiPlatform \Metadata \GraphQl \Query ;
20- use ApiPlatform \State \Pagination \ArrayPaginator ;
2120use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
21+ use ApiPlatform \State \Pagination \ArrayPaginator ;
2222use ApiPlatform \State \ProcessorInterface ;
2323use ApiPlatform \State \ProviderInterface ;
2424use GraphQL \Type \Definition \ResolveInfo ;
@@ -34,17 +34,19 @@ public function __construct(
3434 public function __invoke (?string $ resourceClass = null , ?string $ rootClass = null , ?Operation $ operation = null , ?PropertyMetadataFactoryInterface $ propertyMetadataFactory = null ): callable
3535 {
3636 return function (?array $ source , array $ args , $ context , ResolveInfo $ info ) use ($ resourceClass , $ rootClass , $ operation , $ propertyMetadataFactory ) {
37- if ($ body = $ source [$ info ->fieldName ] ?? null ) {
38- // special treatment for nested resources without a resolver/provider
39-
40- return $ body ;
41- }
42-
4337 if (\array_key_exists ($ info ->fieldName , $ source ?? [])) {
4438 $ body = $ source [$ info ->fieldName ];
4539
40+ // special treatment for nested resources without a resolver/provider
4641 if ($ operation instanceof Query && $ operation ->getNested () && !$ operation ->getResolver () && (!$ operation ->getProvider () || NoopProvider::class === $ operation ->getProvider ())) {
47- return $ this ->resolve ($ source , $ args , $ info , $ rootClass , $ operation , new ArrayPaginator ($ body , 0 , \count ($ body )));
42+ return \is_array ($ body ) ? $ this ->resolve (
43+ $ source ,
44+ $ args ,
45+ $ info ,
46+ $ rootClass ,
47+ $ operation ,
48+ new ArrayPaginator ($ body , 0 , \count ($ body ))
49+ ) : $ body ;
4850 }
4951
5052 $ propertyMetadata = $ rootClass ? $ propertyMetadataFactory ?->create($ rootClass , $ info ->fieldName ) : null ;
0 commit comments