1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Plugin\GraphQL\Traits; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\PluginInspectionInterface; |
6
|
|
|
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface; |
7
|
|
|
use Youshido\GraphQL\Field\InputField; |
8
|
|
|
use Youshido\GraphQL\Type\TypeInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Methods for argument aware plugins. |
12
|
|
|
*/ |
13
|
|
|
trait ArgumentAwarePluginTrait { |
14
|
|
|
use TypedPluginTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Build the arguments list. |
18
|
|
|
* |
19
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
20
|
|
|
* Instance of the schema manager to resolve dependencies. |
21
|
|
|
* |
22
|
|
|
* @return \Youshido\GraphQL\Field\InputFieldInterface[] |
23
|
|
|
* The list of arguments. |
24
|
|
|
*/ |
25
|
|
|
protected function buildArguments(PluggableSchemaBuilderInterface $schemaBuilder) { |
26
|
|
|
$arguments = []; |
27
|
|
|
|
28
|
|
|
if ($this instanceof PluginInspectionInterface) { |
|
|
|
|
29
|
|
|
$definition = $this->getPluginDefinition(); |
30
|
|
|
|
31
|
|
|
foreach ($definition['arguments'] as $name => $argument) { |
32
|
|
|
$type = $this->buildArgumentType($schemaBuilder, $argument); |
33
|
|
|
|
34
|
|
|
$arguments[$name] = new InputField([ |
35
|
|
|
'name' => $name, |
36
|
|
|
'type' => $type, |
37
|
|
|
'defaultValue' => is_array($argument) && isset($argument['default']) ? $argument['default'] : NULL, |
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $arguments; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Build the argument type. |
47
|
|
|
* |
48
|
|
|
* @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder |
49
|
|
|
* Instance of the schema manager to resolve dependencies. |
50
|
|
|
* @param array|string $argument |
51
|
|
|
* The argument definition array or type name. |
52
|
|
|
* |
53
|
|
|
* @return \Youshido\GraphQL\Type\TypeInterface |
54
|
|
|
* The type object. |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
protected function buildArgumentType(PluggableSchemaBuilderInterface $schemaBuilder, $argument) { |
|
|
|
|
57
|
|
|
$type = is_array($argument) ? $argument['type'] : $argument; |
58
|
|
|
return $this->parseType($type, function ($type) use ($schemaBuilder) { |
59
|
|
|
return $schemaBuilder->findByDataTypeOrName($type, [ |
60
|
|
|
GRAPHQL_INPUT_TYPE_PLUGIN, |
61
|
|
|
GRAPHQL_SCALAR_PLUGIN, |
62
|
|
|
GRAPHQL_ENUM_PLUGIN, |
63
|
|
|
])->getDefinition($schemaBuilder); |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
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.