api-platform / api-platform/core

Resolvers are not run on the default deletion mutation

未關閉
#5,425 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
GraphQL State
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 4 小時
30 天內合併 PR
49

描述

**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()));
}
}
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。