1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Mutation; |
12
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Error\NodeNotFoundException; |
14
|
|
|
use Ynlo\GraphQLBundle\Extension\ExtensionManager; |
15
|
|
|
use Ynlo\GraphQLBundle\Model\DeleteNodePayload; |
16
|
|
|
use Ynlo\GraphQLBundle\Model\ID; |
17
|
|
|
use Ynlo\GraphQLBundle\Model\NodeInterface; |
18
|
|
|
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class DeleteNodeMutation |
22
|
|
|
*/ |
23
|
|
|
class DeleteNode extends AbstractMutationResolver |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
2 |
View Code Duplication |
protected function process(&$data) |
|
|
|
|
29
|
|
|
{ |
30
|
2 |
|
$this->preDelete($data); |
31
|
2 |
|
foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) { |
32
|
|
|
$extension->preDelete($data, $this, $this->context); |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
$this->getManager()->remove($data); |
36
|
2 |
|
$this->getManager()->flush(); |
37
|
|
|
|
38
|
2 |
|
$this->postDelete($data); |
39
|
2 |
|
foreach ($this->container->get(ExtensionManager::class)->getExtensions() as $extension) { |
40
|
|
|
$extension->postDelete($data, $this, $this->context); |
41
|
|
|
} |
42
|
2 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
2 |
|
protected function returnPayload($data, ConstraintViolationList $violations, $inputSource) |
48
|
|
|
{ |
49
|
2 |
|
return new DeleteNodePayload( |
50
|
2 |
|
$inputSource['id'] ? ID::createFromString($inputSource['id']) : null, |
|
|
|
|
51
|
2 |
|
$inputSource['clientMutationId'] ?? null |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
2 |
|
protected function onSubmit($inputSource, &$normData) |
59
|
|
|
{ |
60
|
2 |
|
if ($normData instanceof NodeInterface && $normData->getId()) { |
|
|
|
|
61
|
2 |
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
throw new NodeNotFoundException(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param NodeInterface $node |
69
|
|
|
*/ |
70
|
2 |
|
protected function preDelete(NodeInterface $node) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
//override |
73
|
2 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param NodeInterface $node |
77
|
|
|
*/ |
78
|
2 |
|
protected function postDelete(NodeInterface $node) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
//override |
81
|
2 |
|
} |
82
|
|
|
} |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.