|
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\Definition\Loader\Annotation; |
|
12
|
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Annotation; |
|
14
|
|
|
use Ynlo\GraphQLBundle\Definition\MutationDefinition; |
|
15
|
|
|
use Ynlo\GraphQLBundle\Definition\Registry\DefinitionManager; |
|
16
|
|
|
use Ynlo\GraphQLBundle\Model\DeleteNodePayload; |
|
17
|
|
|
use Ynlo\GraphQLBundle\Mutation\DeleteNodeMutation; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Resolve queries |
|
21
|
|
|
*/ |
|
22
|
|
|
class MutationDeleteAnnotationParser extends MutationAnnotationParser |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function supports($annotation): bool |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $annotation instanceof Annotation\MutationDelete; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function parse($annotation, \ReflectionClass $refClass, DefinitionManager $definitionManager) |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var Annotation\MutationDelete $annotation */ |
|
38
|
1 |
|
if (!$annotation->name) { |
|
39
|
1 |
|
$annotation->name = 'delete'.ucfirst($this->getDefaultName($refClass, $definitionManager)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
if ($definitionManager->hasTypeForClass($refClass->getName())) { |
|
43
|
1 |
|
$annotation->formOptions = array_merge(['data_class' => $refClass->getName()], $annotation->formOptions); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
parent::parse($annotation, $refClass, $definitionManager); |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function createMutation(Annotation\Mutation $annotation): MutationDefinition |
|
53
|
|
|
{ |
|
54
|
1 |
|
$mutation = parent::createMutation($annotation); |
|
55
|
1 |
|
if (!$annotation->resolver) { |
|
56
|
1 |
|
$mutation->setResolver(DeleteNodeMutation::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
if (!$annotation->payload) { |
|
60
|
1 |
|
$mutation->setType(DeleteNodePayload::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
return $mutation; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|