api-platform / api-platform/core

Resolvers are not run on the default deletion mutation

Đang mở
#5,425 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
GraphQL State
Ngôn ngữ chính
PHP
Star
2.6k
Fork
980
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
49

Mô tả

**API Platform version(s) affected**: 3.1.3

**Description**
With GraphQL when we try to add a resolver on the delete mutation it doesn't work. It is not executed.

**How to reproduce**
```php
#[ApiResource(
graphQlOperations: [
new Mutation(
resolver: CreateResolver::class,
args: [
'test' => [
'type' => 'String!',
]
],
name: 'create'
),
new DeleteMutation(
resolver: DeleteResolver::class,
args: [
'id' => [
'type' => 'ID!',
],
],
name: 'delete',
)
]
)]

```

**Possible Solution**

In src/GraphQl/Resolver/Factory/ItemMutationResolverFactory.php If the operation is "delete" the resolver are not executed because the resolver are executed after.
```php
if ('delete' === $operation->getName() || $operation instanceof DeleteOperationInterface) {
($this->securityPostDenormalizeStage)($resourceClass, $operation, $resolverContext + [
'extra_variables' => [
'object' => $item,
'previous_object' => $previousItem,
],
]);
$item = ($this->writeStage)($item, $resourceClass, $operation, $resolverContext);

return ($this->serializeStage)($item, $resourceClass, $operation, $resolverContext);
}

$item = ($this->deserializeStage)($item, $resourceClass, $operation, $resolverContext);

$mutationResolverId = $operation->getResolver();
if (null !== $mutationResolverId) {
/** @var MutationResolverInterface $mutationResolver */
$mutationResolver = $this->mutationResolverLocator->get($mutationResolverId);
$item = $mutationResolver($item, $resolverContext);
if (null !== $item && $resourceClass !== $itemClass = $this->getObjectClass($item)) {
throw new \LogicException(sprintf('Custom mutation resolver "%s" has to return an item of class %s but returned an item of class %s.', $mutationResolverId, $operation->getShortName(), (new \ReflectionClass($itemClass))->getShortName()));
}
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.