17
17
use ApiPlatform \Metadata \GraphQl \Mutation ;
18
18
use ApiPlatform \Metadata \GraphQl \Operation ;
19
19
use ApiPlatform \Metadata \GraphQl \Query ;
20
- use ApiPlatform \State \Pagination \ArrayPaginator ;
21
20
use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
21
+ use ApiPlatform \State \Pagination \ArrayPaginator ;
22
22
use ApiPlatform \State \ProcessorInterface ;
23
23
use ApiPlatform \State \ProviderInterface ;
24
24
use GraphQL \Type \Definition \ResolveInfo ;
@@ -34,17 +34,19 @@ public function __construct(
34
34
public function __invoke (?string $ resourceClass = null , ?string $ rootClass = null , ?Operation $ operation = null , ?PropertyMetadataFactoryInterface $ propertyMetadataFactory = null ): callable
35
35
{
36
36
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
-
43
37
if (\array_key_exists ($ info ->fieldName , $ source ?? [])) {
44
38
$ body = $ source [$ info ->fieldName ];
45
39
40
+ // special treatment for nested resources without a resolver/provider
46
41
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 ;
48
50
}
49
51
50
52
$ propertyMetadata = $ rootClass ? $ propertyMetadataFactory ?->create($ rootClass , $ info ->fieldName ) : null ;
0 commit comments