|
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\UpdateNodePayload; |
|
17
|
|
|
use Ynlo\GraphQLBundle\Mutation\UpdateNodeMutation; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Resolve queries |
|
21
|
|
|
*/ |
|
22
|
|
View Code Duplication |
class MutationUpdateAnnotationParser extends MutationAnnotationParser |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function supports($annotation): bool |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $annotation instanceof Annotation\MutationUpdate; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function parse($annotation, \ReflectionClass $refClass, DefinitionManager $definitionManager) |
|
36
|
|
|
{ |
|
37
|
1 |
|
if (!$annotation->name) { |
|
38
|
1 |
|
$annotation->name = 'update'.ucfirst($this->getDefaultName($refClass, $definitionManager)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
parent::parse($annotation, $refClass, $definitionManager); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function createMutation(Annotation\Mutation $annotation): MutationDefinition |
|
48
|
|
|
{ |
|
49
|
1 |
|
$mutation = parent::createMutation($annotation); |
|
50
|
1 |
|
if (!$annotation->resolver) { |
|
51
|
1 |
|
$mutation->setResolver(UpdateNodeMutation::class); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
if (!$annotation->payload) { |
|
55
|
1 |
|
$mutation->setType(UpdateNodePayload::class); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
return $mutation; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.