Skip to content

Commit 23e0eb1

Browse files
committed
Use collection resolver for mutations
1 parent 3bcf0e8 commit 23e0eb1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/GraphQl/Resolver/Factory/CollectionResolverFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use 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 = [];

src/GraphQl/Type/SchemaBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ private function getResourceFieldConfiguration(string $resourceClass, ResourceMe
249249
$args = $this->convertFilterArgsToTypes($args);
250250
}
251251

252-
if ($isInternalGraphqlType || $input || null !== $mutationName) {
252+
if ($isInternalGraphqlType || $input) {
253253
$resolve = null;
254254
} elseif ($this->isCollection($type)) {
255255
$resolverFactory = $this->collectionResolverFactory;
256-
$resolve = $resolverFactory($className, $rootResource);
256+
$resolve = $resolverFactory($className, $rootResource, $mutationName);
257257
} else {
258258
$resolve = $this->itemResolver;
259259
}

0 commit comments

Comments
 (0)