2828use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
2929
3030/**
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 .
3232 *
3333 * @experimental
3434 *
@@ -62,7 +62,7 @@ public function __construct(CollectionDataProviderInterface $collectionDataProvi
6262
6363 public function __invoke (string $ resourceClass = null , string $ rootClass = null , string $ operationName = null ): callable
6464 {
65- return function ($ source , $ args , $ context , ResolveInfo $ info ) use ($ resourceClass , $ rootClass ) {
65+ return function ($ source , $ args , $ context , ResolveInfo $ info ) use ($ resourceClass , $ rootClass, $ operationName ) {
6666 if (null === $ resourceClass ) {
6767 return null ;
6868 }
@@ -75,7 +75,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
7575 }
7676
7777 $ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ resourceClass );
78- $ dataProviderContext = $ resourceMetadata ->getGraphqlAttribute ('query ' , 'normalization_context ' , [], true );
78+ $ dataProviderContext = $ resourceMetadata ->getGraphqlAttribute ($ operationName ?? 'query ' , 'normalization_context ' , [], true );
7979 $ dataProviderContext ['attributes ' ] = $ this ->fieldsToAttributes ($ info );
8080 $ dataProviderContext ['filters ' ] = $ this ->getNormalizedFilters ($ args );
8181
@@ -87,7 +87,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
8787 $ collection = $ this ->collectionDataProvider ->getCollection ($ resourceClass , null , $ dataProviderContext );
8888 }
8989
90- $ this ->canAccess ($ this ->resourceAccessChecker , $ resourceMetadata , $ resourceClass , $ info , $ collection , 'query ' );
90+ $ this ->canAccess ($ this ->resourceAccessChecker , $ resourceMetadata , $ resourceClass , $ info , $ collection , $ operationName ?? 'query ' );
9191
9292 if (!$ this ->paginationEnabled ) {
9393 $ data = [];
0 commit comments