1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\GraphQL\Field; |
4
|
|
|
|
5
|
|
|
use Drupal\graphql\GraphQL\CacheableEdgeInterface; |
6
|
|
|
use Drupal\graphql\GraphQL\CacheableEdgeTrait; |
7
|
|
|
use Drupal\graphql\GraphQL\PluginReferenceInterface; |
8
|
|
|
use Drupal\graphql\GraphQL\PluginReferenceTrait; |
9
|
|
|
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; |
10
|
|
|
use Drupal\graphql\Plugin\GraphQL\Mutations\MutationPluginBase; |
11
|
|
|
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface; |
12
|
|
|
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface; |
13
|
|
|
use Youshido\GraphQL\Config\Field\FieldConfig; |
14
|
|
|
use Youshido\GraphQL\Execution\ResolveInfo; |
15
|
|
|
use Youshido\GraphQL\Field\AbstractField; |
16
|
|
|
|
17
|
|
|
class Field extends AbstractField implements PluginReferenceInterface, CacheableEdgeInterface { |
18
|
|
|
use PluginReferenceTrait; |
19
|
|
|
use CacheableEdgeTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function __construct(TypeSystemPluginInterface $plugin, PluggableSchemaBuilderInterface $builder, array $config = []) { |
25
|
|
|
$this->plugin = $plugin; |
26
|
|
|
$this->builder = $builder; |
27
|
|
|
$this->config = new FieldConfig($config, $this, TRUE); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function resolve($value, array $args, ResolveInfo $info) { |
34
|
|
|
if (($plugin = $this->getPlugin()) && ($plugin instanceof FieldPluginBase || $plugin instanceof MutationPluginBase)) { |
35
|
|
|
return $plugin->resolve($value, $args, $info); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return NULL; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getType() { |
45
|
|
|
return $this->getConfigValue('type'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getName() { |
52
|
|
|
return $this->getConfigValue('name'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: