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\Extension\ExtensionManager; |
16
|
|
|
use Ynlo\GraphQLBundle\Model\NodeInterface; |
17
|
|
|
use Ynlo\GraphQLBundle\Model\UpdateNodePayload; |
18
|
|
|
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class UpdateNodeMutation |
22
|
|
|
*/ |
23
|
|
|
class UpdateNode extends AbstractMutationResolver |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
1 |
|
public function process(&$data) |
29
|
|
|
{ |
30
|
1 |
|
$this->preUpdate($data); |
31
|
1 |
|
foreach ($this->extensions as $extension) { |
32
|
|
|
$extension->preUpdate($data, $this, $this->context); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
$this->getManager()->flush(); |
36
|
|
|
|
37
|
1 |
|
$this->postUpdate($data); |
38
|
1 |
|
foreach ($this->extensions as $extension) { |
39
|
|
|
$extension->postUpdate($data, $this, $this->context); |
40
|
|
|
} |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
1 |
|
public function onSubmit(FormEvent $event) |
47
|
|
|
{ |
48
|
1 |
|
if (!$event->getData() instanceof NodeInterface || !$event->getData()->getId()) { |
|
|
|
|
49
|
|
|
throw new NodeNotFoundException(); |
50
|
|
|
} |
51
|
1 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
1 |
View Code Duplication |
public function returnPayload($data, ConstraintViolationList $violations, $inputSource) |
|
|
|
|
57
|
|
|
{ |
58
|
1 |
|
if ($violations->count()) { |
59
|
|
|
$data = null; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
return new UpdateNodePayload($data, $violations->all(), $inputSource['clientMutationId'] ?? null); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param NodeInterface $node |
67
|
|
|
*/ |
68
|
1 |
|
protected function preUpdate(NodeInterface $node) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
//override |
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param NodeInterface $node |
75
|
|
|
*/ |
76
|
1 |
|
protected function postUpdate(NodeInterface $node) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
//override |
79
|
1 |
|
} |
80
|
|
|
} |
81
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: