From 20dc21182890b85deb5baef68273cd24a0abd984 Mon Sep 17 00:00:00 2001 From: Brett Ludwig Date: Wed, 16 Jul 2025 12:23:29 -0600 Subject: [PATCH 1/3] Update state-processors.md State processor clarification for graphql operations. --- core/state-processors.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/state-processors.md b/core/state-processors.md index 28137a95fd1..3e212f89874 100644 --- a/core/state-processors.md +++ b/core/state-processors.md @@ -139,6 +139,14 @@ class BlogPost {} ### Symfony State Processor mechanism If you want to execute custom business logic before or after persistence, this can be achieved by using [composition](https://en.wikipedia.org/wiki/Object_composition). +For GraphQL a remove Operation type will not be `DeleteOperationInterface` type but `ApiPlatform\Metadata\GraphQl\Mutation` with a `getName()` result of "delete". You can insert this to use the `$removeProcessor`: + +``` + if ($operation instanceof \ApiPlatform\Metadata\GraphQl\Mutation && $operation->getName() === 'delete') { + return $this->removeProcessor->process($data, $operation, $uriVariables, $context); + } +``` + Here is an implementation example which uses [Symfony Mailer](https://symfony.com/doc/current/mailer.html) to send new users a welcome email after a REST `POST` or GraphQL `create` operation, in a project using the native Doctrine ORM state processor: ```php From 62578de5d21486662164849c9fc17bf13bfb296f Mon Sep 17 00:00:00 2001 From: Brett Ludwig Date: Wed, 16 Jul 2025 12:37:25 -0600 Subject: [PATCH 2/3] Update state-processors.md - return ID required --- core/state-processors.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/state-processors.md b/core/state-processors.md index 3e212f89874..0fb3acf5554 100644 --- a/core/state-processors.md +++ b/core/state-processors.md @@ -139,11 +139,13 @@ class BlogPost {} ### Symfony State Processor mechanism If you want to execute custom business logic before or after persistence, this can be achieved by using [composition](https://en.wikipedia.org/wiki/Object_composition). -For GraphQL a remove Operation type will not be `DeleteOperationInterface` type but `ApiPlatform\Metadata\GraphQl\Mutation` with a `getName()` result of "delete". You can insert this to use the `$removeProcessor`: +For GraphQL a remove Operation type will not be `DeleteOperationInterface` type but `ApiPlatform\Metadata\GraphQl\Mutation` with a `getName()` result of "delete". You can insert this to use the `$removeProcessor`. However, API Platform will not return the object in this case (which is required in the GraphQL schema on a delete op) so you'll need to create a temporary object to return: ``` if ($operation instanceof \ApiPlatform\Metadata\GraphQl\Mutation && $operation->getName() === 'delete') { - return $this->removeProcessor->process($data, $operation, $uriVariables, $context); + $returnEntity = clone $data; + $this->removeProcessor->process($data, $operation, $uriVariables, $context); + return $returnEntity; } ``` From acffc42a90c5767160233f1c2954f728af98205e Mon Sep 17 00:00:00 2001 From: Brett Ludwig Date: Wed, 16 Jul 2025 12:56:01 -0600 Subject: [PATCH 3/3] added php tag for syntax highlighting --- core/state-processors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/state-processors.md b/core/state-processors.md index 0fb3acf5554..da499285517 100644 --- a/core/state-processors.md +++ b/core/state-processors.md @@ -141,7 +141,7 @@ If you want to execute custom business logic before or after persistence, this c For GraphQL a remove Operation type will not be `DeleteOperationInterface` type but `ApiPlatform\Metadata\GraphQl\Mutation` with a `getName()` result of "delete". You can insert this to use the `$removeProcessor`. However, API Platform will not return the object in this case (which is required in the GraphQL schema on a delete op) so you'll need to create a temporary object to return: -``` +```php if ($operation instanceof \ApiPlatform\Metadata\GraphQl\Mutation && $operation->getName() === 'delete') { $returnEntity = clone $data; $this->removeProcessor->process($data, $operation, $uriVariables, $context);