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