1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Drupal\graphql\GraphQL\Utility\Plugin\GraphQL\Mutations; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\PluginBase; |
6
|
|
|
use Drupal\graphql\Plugin\MutationPluginInterface; |
7
|
|
|
use Drupal\graphql\Plugin\MutationPluginManager; |
8
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\ArgumentAwarePluginTrait; |
9
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\DeprecatablePluginTrait; |
10
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\DescribablePluginTrait; |
11
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\TypedPluginTrait; |
12
|
|
|
use Drupal\graphql\Plugin\SchemaBuilderInterface; |
13
|
|
|
|
14
|
|
View Code Duplication |
abstract class MutationPluginBase extends PluginBase implements MutationPluginInterface { |
|
|
|
|
15
|
|
|
use TypedPluginTrait; |
16
|
|
|
use DescribablePluginTrait; |
17
|
|
|
use ArgumentAwarePluginTrait; |
18
|
|
|
use DeprecatablePluginTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
public static function createInstance(SchemaBuilderInterface $builder, MutationPluginManager $manager, $definition, $id) { |
24
|
|
|
return [ |
25
|
|
|
'description' => $definition['description'], |
26
|
|
|
'deprecationReason' => $definition['deprecationReason'], |
27
|
|
|
'type' => $builder->processType($definition['type']), |
28
|
|
|
'args' => $builder->processArguments($definition['args']), |
29
|
|
|
'resolve' => function ($value, $args, $context, $info) use ($manager, $id) { |
30
|
|
|
$instance = $manager->getInstance(['id' => $id]); |
31
|
|
|
return call_user_func_array([$instance, 'resolve'], [$value, $args, $context, $info]); |
32
|
|
|
}, |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function getDefinition() { |
40
|
|
|
$definition = $this->getPluginDefinition(); |
41
|
|
|
|
42
|
|
|
return [ |
43
|
|
|
'type' => $this->buildType($definition), |
44
|
|
|
'description' => $this->buildDescription($definition), |
45
|
|
|
'args' => $this->buildArguments($definition), |
46
|
|
|
'deprecationReason' => $this->buildDeprecationReason($definition), |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
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.