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\Extension\ExtensionManager; |
14
|
|
|
use Ynlo\GraphQLBundle\Model\AddNodePayload; |
15
|
|
|
use Ynlo\GraphQLBundle\Model\NodeInterface; |
16
|
|
|
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class AddNode |
20
|
|
|
*/ |
21
|
|
|
class AddNode extends AbstractMutationResolver |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
5 |
|
public function process(&$data) |
27
|
|
|
{ |
28
|
5 |
|
$this->prePersist($data); |
29
|
5 |
|
foreach ($this->extensions as $extension) { |
30
|
4 |
|
$extension->prePersist($data, $this, $this->context); |
31
|
|
|
} |
32
|
|
|
|
33
|
5 |
|
$this->getManager()->persist($data); |
34
|
5 |
|
$this->getManager()->flush(); |
35
|
|
|
|
36
|
5 |
|
$this->postPersist($data); |
37
|
5 |
|
foreach ($this->extensions as $extension) { |
38
|
4 |
|
$extension->postPersist($data, $this, $this->context); |
39
|
|
|
} |
40
|
5 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
6 |
|
public function returnPayload($data, ConstraintViolationList $violations, $inputSource) |
46
|
|
|
{ |
47
|
6 |
|
if ($violations->count()) { |
48
|
1 |
|
$data = null; |
49
|
|
|
} |
50
|
|
|
|
51
|
6 |
|
return new AddNodePayload($data, $violations->all(), $inputSource['clientMutationId'] ?? null); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param NodeInterface $node |
56
|
|
|
*/ |
57
|
5 |
|
protected function prePersist(NodeInterface $node) |
58
|
|
|
{ |
59
|
|
|
//override |
60
|
5 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param NodeInterface $node |
64
|
|
|
*/ |
65
|
5 |
|
protected function postPersist(NodeInterface $node) |
66
|
|
|
{ |
67
|
|
|
//override |
68
|
5 |
|
} |
69
|
|
|
} |
70
|
|
|
|