|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Date: 03.12.15 |
|
4
|
|
|
* |
|
5
|
|
|
* @author Portey Vasil <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL\Introspection; |
|
9
|
|
|
|
|
10
|
|
|
use Youshido\GraphQL\Field\Field; |
|
11
|
|
|
use Youshido\GraphQL\Schema\AbstractSchema; |
|
12
|
|
|
use Youshido\GraphQL\Type\NonNullType; |
|
13
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
|
14
|
|
|
use Youshido\GraphQL\Type\TypeInterface; |
|
15
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
|
16
|
|
|
|
|
17
|
|
|
class InputValueType extends AbstractObjectType |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param AbstractSchema|Field $value |
|
21
|
|
|
* |
|
22
|
|
|
* @return TypeInterface |
|
23
|
|
|
*/ |
|
24
|
2 |
|
public function resolveType($value) |
|
25
|
|
|
{ |
|
26
|
2 |
|
return $value->getConfig()->getType(); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param AbstractSchema|Field $value |
|
31
|
|
|
* |
|
32
|
|
|
* @return string|null |
|
33
|
|
|
*/ |
|
34
|
3 |
|
public function resolveDefaultValue($value) |
|
35
|
|
|
{ |
|
36
|
3 |
|
$resolvedValue = $value->getConfig()->getDefaultValue(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
3 |
|
return $resolvedValue === null ? $resolvedValue : json_encode($resolvedValue); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
5 |
View Code Duplication |
public function build($config) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$config |
|
44
|
5 |
|
->addField('name', new NonNullType(TypeMap::TYPE_STRING)) |
|
45
|
5 |
|
->addField('description', TypeMap::TYPE_STRING) |
|
46
|
5 |
|
->addField(new Field([ |
|
47
|
5 |
|
'name' => 'type', |
|
48
|
5 |
|
'type' => new NonNullType(new QueryType()), |
|
49
|
5 |
|
'resolve' => [$this, 'resolveType'] |
|
50
|
|
|
])) |
|
51
|
5 |
|
->addField('defaultValue', [ |
|
52
|
5 |
|
'type' => TypeMap::TYPE_STRING, |
|
53
|
5 |
|
'resolve' => [$this, 'resolveDefaultValue'] |
|
54
|
|
|
]); |
|
55
|
5 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string type name |
|
59
|
|
|
*/ |
|
60
|
7 |
|
public function getName() |
|
61
|
|
|
{ |
|
62
|
7 |
|
return '__InputValue'; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
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: