Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/state-processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ 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`. 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);
return $returnEntity;
}
```

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
Expand Down