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\Exception\Controlled\NotFoundError; |
15
|
|
|
use Ynlo\GraphQLBundle\Model\NodeInterface; |
16
|
|
|
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class UpdateNodeMutation |
20
|
|
|
*/ |
21
|
|
|
class UpdateNode extends AbstractMutationResolver |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function process(&$data) |
27
|
|
|
{ |
28
|
|
|
$this->preUpdate($data); |
29
|
|
|
foreach ($this->extensions as $extension) { |
30
|
|
|
$extension->preUpdate($data, $this, $this->context); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$this->getManager()->flush(); |
34
|
|
|
|
35
|
|
|
$this->postUpdate($data); |
36
|
|
|
foreach ($this->extensions as $extension) { |
37
|
|
|
$extension->postUpdate($data, $this, $this->context); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
*/ |
44
|
|
|
public function onSubmit(FormEvent $event) |
45
|
|
|
{ |
46
|
|
|
if (!$event->getData() instanceof NodeInterface || !$event->getData()->getId()) { |
47
|
|
|
throw new NotFoundError(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function returnPayload($data, ConstraintViolationList $violations, $inputSource) |
55
|
|
|
{ |
56
|
|
|
if ($violations->count()) { |
57
|
|
|
$data = null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$class = $this->getPayloadClass(); |
61
|
|
|
|
62
|
|
|
return new $class($data, $violations->all(), $inputSource['clientMutationId'] ?? null); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param NodeInterface $node |
67
|
|
|
*/ |
68
|
|
|
protected function preUpdate(NodeInterface $node) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
//override |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param NodeInterface $node |
75
|
|
|
*/ |
76
|
|
|
protected function postUpdate(NodeInterface $node) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
//override |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.