|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Plugin\GraphQL; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\ConfigurablePluginInterface; |
|
6
|
|
|
use Drupal\graphql\GraphQL\Schema\Schema; |
|
7
|
|
|
use Youshido\GraphQL\Execution\ResolveInfo; |
|
8
|
|
|
|
|
9
|
|
|
trait TypeSystemPluginReferenceTrait { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* The associated type system plugin. |
|
13
|
|
|
* |
|
14
|
|
|
* @var \Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $plugin; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Retrieves the corresponding plugin instance from the resolve info. |
|
20
|
|
|
* |
|
21
|
|
|
* @param \Youshido\GraphQL\Execution\ResolveInfo $info |
|
22
|
|
|
* The resolve info object. |
|
23
|
|
|
* |
|
24
|
|
|
* @return \Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface|null |
|
25
|
|
|
* The corresponding plugin instance for this edge. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function getPluginFromResolveInfo(ResolveInfo $info) { |
|
28
|
|
|
if (is_array($this->plugin)) { |
|
29
|
|
|
$schema = isset($info) ? $info->getExecutionContext()->getSchema() : NULL; |
|
30
|
|
|
if (!$schema instanceof Schema) { |
|
31
|
|
|
return NULL; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$schemaPlugin = $schema->getSchemaPlugin(); |
|
35
|
|
|
if (!$schemaPlugin instanceof PluggableSchemaPluginInterface) { |
|
36
|
|
|
return NULL; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$typePlugin = $this->getPlugin($schemaPlugin->getSchemaBuilder()); |
|
40
|
|
|
if (!$typePlugin instanceof TypeSystemPluginInterface) { |
|
41
|
|
|
return NULL; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $typePlugin; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ($this->plugin instanceof TypeSystemPluginInterface) { |
|
48
|
|
|
return $this->plugin; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return NULL; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getPlugin(PluggableSchemaBuilderInterface $schemaBuilder) { |
|
58
|
|
|
if (is_array($this->plugin)) { |
|
59
|
|
|
$this->plugin = $schemaBuilder->getInstance( |
|
60
|
|
|
$this->plugin['type'], |
|
61
|
|
|
$this->plugin['id'], |
|
62
|
|
|
$this->plugin['configuration'] |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ($this->plugin instanceof TypeSystemPluginInterface) { |
|
67
|
|
|
return $this->plugin; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return NULL; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __sleep() { |
|
77
|
|
|
// Instead of serializing the referenced plugin, we just serialize the |
|
78
|
|
|
// plugin id and configuration. |
|
79
|
|
|
$this->plugin = [ |
|
|
|
|
|
|
80
|
|
|
'id' => $this->plugin->getPluginId(), |
|
81
|
|
|
'type' => $this->plugin->getPluginDefinition()['pluginType'], |
|
82
|
|
|
'configuration' => $this->plugin instanceof ConfigurablePluginInterface ? $this->plugin->getConfiguration() : [], |
|
|
|
|
|
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
return array_keys(get_object_vars($this)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..