core
core copied to clipboard
Resolvers are not run on the default deletion mutation
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
#[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.
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()));
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still buggy in 3.1.10
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
A fix is coming in 3.2
Any news on this ?
@cuberinooo I updated from v.3.2.19 to v.3.3.9 and it seems to work now.