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