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 Symfony\Component\Form\FormEvent; |
14
|
|
|
use Ynlo\GraphQLBundle\Error\NodeNotFoundException; |
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 |
|
public function process(&$data) |
29
|
|
|
{ |
30
|
2 |
|
$this->preDelete($data); |
31
|
2 |
|
foreach ($this->extensions as $extension) { |
32
|
1 |
|
$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->extensions as $extension) { |
40
|
1 |
|
$extension->postDelete($data, $this, $this->context); |
41
|
|
|
} |
42
|
2 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
2 |
|
public 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 |
|
public function onSubmit(FormEvent $event) |
59
|
|
|
{ |
60
|
2 |
|
$node = $this->context->getDefinition()->getNode(); |
61
|
2 |
|
$class = $this->context->getEndpoint()->getClassForType($node); |
62
|
|
|
|
63
|
2 |
|
if (!$event->getData() instanceof NodeInterface || !$event->getData()->getId() || !is_a($event->getData(), $class)) { |
64
|
|
|
throw new NodeNotFoundException(); |
65
|
|
|
} |
66
|
2 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param NodeInterface $node |
70
|
|
|
*/ |
71
|
2 |
|
protected function preDelete(NodeInterface $node) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
//override |
74
|
2 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param NodeInterface $node |
78
|
|
|
*/ |
79
|
2 |
|
protected function postDelete(NodeInterface $node) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
//override |
82
|
2 |
|
} |
83
|
|
|
} |
84
|
|
|
|