1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Plugin\GraphQL\InputTypes; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\PluginBase; |
6
|
|
|
use Drupal\Component\Plugin\PluginInspectionInterface; |
7
|
|
|
use Drupal\graphql\GraphQL\Type\InputObjectType; |
8
|
|
|
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface; |
9
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\CacheablePluginTrait; |
10
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\NamedPluginTrait; |
11
|
|
|
use Drupal\graphql\Plugin\GraphQL\Traits\TypedPluginTrait; |
12
|
|
|
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface; |
13
|
|
|
use Youshido\GraphQL\Field\Field; |
14
|
|
|
use Youshido\GraphQL\Type\TypeInterface; |
15
|
|
|
|
16
|
|
|
abstract class InputTypePluginBase extends PluginBase implements TypeSystemPluginInterface { |
17
|
|
|
use CacheablePluginTrait; |
18
|
|
|
use NamedPluginTrait; |
19
|
|
|
use TypedPluginTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The type instance. |
23
|
|
|
* |
24
|
|
|
* @var \Drupal\graphql\GraphQL\Type\InputObjectType |
25
|
|
|
*/ |
26
|
|
|
protected $definition; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function getDefinition(PluggableSchemaBuilderInterface $schemaBuilder) { |
32
|
|
|
if (!isset($this->definition)) { |
33
|
|
|
$this->definition = new InputObjectType($this, $schemaBuilder, [ |
34
|
|
|
'name' => $this->buildName(), |
35
|
|
|
'description' => $this->buildDescription(), |
36
|
|
|
'fields' => $this->buildFields($schemaBuilder), |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->definition; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Build the field list. |
45
|
|
|
* |
46
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
47
|
|
|
* Instance of the schema manager to resolve dependencies. |
48
|
|
|
* |
49
|
|
|
* @return \Youshido\GraphQL\Field\FieldInterface[] |
50
|
|
|
* The list of fields. |
51
|
|
|
*/ |
52
|
|
|
protected function buildFields(PluggableSchemaBuilderInterface $schemaBuilder) { |
53
|
|
|
if ($this instanceof PluginInspectionInterface) { |
|
|
|
|
54
|
|
|
$definition = $this->getPluginDefinition(); |
55
|
|
|
if (!$definition['fields']) { |
56
|
|
|
return []; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$arguments = []; |
60
|
|
|
foreach ($definition['fields'] as $name => $argument) { |
61
|
|
|
$type = $this->buildFieldType($schemaBuilder, $argument); |
62
|
|
|
|
63
|
|
|
if ($type instanceof TypeInterface) { |
64
|
|
|
$config = [ |
65
|
|
|
'name' => $name, |
66
|
|
|
'type' => $type, |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
if (is_array($argument) && isset($argument['default'])) { |
70
|
|
|
$config['defaultValue'] = $argument['default']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$arguments[$name] = new Field($config); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $arguments; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return []; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Build the field type. |
85
|
|
|
* |
86
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
87
|
|
|
* Instance of the schema manager to resolve dependencies. |
88
|
|
|
* @param array|string $field |
89
|
|
|
* The field definition array or type name. |
90
|
|
|
* |
91
|
|
|
* @return \Youshido\GraphQL\Type\TypeInterface |
92
|
|
|
* The type object. |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
protected function buildFieldType(PluggableSchemaBuilderInterface $schemaBuilder, $field) { |
|
|
|
|
95
|
|
|
$type = is_array($field) ? $field['type'] : $field; |
96
|
|
|
return $this->parseType($type, function ($type) use ($schemaBuilder) { |
97
|
|
|
return $schemaBuilder->findByDataTypeOrName($type, [ |
98
|
|
|
GRAPHQL_INPUT_TYPE_PLUGIN, |
99
|
|
|
GRAPHQL_SCALAR_PLUGIN, |
100
|
|
|
GRAPHQL_ENUM_PLUGIN, |
101
|
|
|
])->getDefinition($schemaBuilder); |
102
|
|
|
}); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.