Skip to content

Commit 62578de

Browse files
authored
Update state-processors.md - return ID required
1 parent 20dc211 commit 62578de

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/state-processors.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ class BlogPost {}
139139
### Symfony State Processor mechanism
140140
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).
141141

142-
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`:
142+
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:
143143

144144
```
145145
if ($operation instanceof \ApiPlatform\Metadata\GraphQl\Mutation && $operation->getName() === 'delete') {
146-
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
146+
$returnEntity = clone $data;
147+
$this->removeProcessor->process($data, $operation, $uriVariables, $context);
148+
return $returnEntity;
147149
}
148150
```
149151

0 commit comments

Comments
 (0)