28
28
use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
29
29
30
30
/**
31
- * Creates a function retrieving a collection to resolve a GraphQL query.
31
+ * Creates a function retrieving a collection to resolve a GraphQL query or a field returned by a mutation .
32
32
*
33
33
* @experimental
34
34
*
@@ -62,7 +62,7 @@ public function __construct(CollectionDataProviderInterface $collectionDataProvi
62
62
63
63
public function __invoke (string $ resourceClass = null , string $ rootClass = null , string $ operationName = null ): callable
64
64
{
65
- return function ($ source , $ args , $ context , ResolveInfo $ info ) use ($ resourceClass , $ rootClass ) {
65
+ return function ($ source , $ args , $ context , ResolveInfo $ info ) use ($ resourceClass , $ rootClass, $ operationName ) {
66
66
if (null === $ resourceClass ) {
67
67
return null ;
68
68
}
@@ -75,7 +75,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
75
75
}
76
76
77
77
$ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ resourceClass );
78
- $ dataProviderContext = $ resourceMetadata ->getGraphqlAttribute ('query ' , 'normalization_context ' , [], true );
78
+ $ dataProviderContext = $ resourceMetadata ->getGraphqlAttribute ($ operationName ?? 'query ' , 'normalization_context ' , [], true );
79
79
$ dataProviderContext ['attributes ' ] = $ this ->fieldsToAttributes ($ info );
80
80
$ dataProviderContext ['filters ' ] = $ this ->getNormalizedFilters ($ args );
81
81
@@ -87,7 +87,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
87
87
$ collection = $ this ->collectionDataProvider ->getCollection ($ resourceClass , null , $ dataProviderContext );
88
88
}
89
89
90
- $ this ->canAccess ($ this ->resourceAccessChecker , $ resourceMetadata , $ resourceClass , $ info , $ collection , 'query ' );
90
+ $ this ->canAccess ($ this ->resourceAccessChecker , $ resourceMetadata , $ resourceClass , $ info , $ collection , $ operationName ?? 'query ' );
91
91
92
92
if (!$ this ->paginationEnabled ) {
93
93
$ data = [];
0 commit comments