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
|
5 |
|
public function resolveType($value) |
25
|
|
|
{ |
26
|
5 |
|
return $value->getConfig()->getType(); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param AbstractSchema|Field $value |
31
|
|
|
* |
32
|
|
|
* @return string|null |
33
|
|
|
* |
34
|
|
|
* //todo implement value printer |
35
|
|
|
*/ |
36
|
6 |
|
public function resolveDefaultValue($value) |
37
|
|
|
{ |
38
|
6 |
|
$resolvedValue = $value->getConfig()->getDefaultValue(); |
|
|
|
|
39
|
6 |
|
return $resolvedValue === null ? $resolvedValue : str_replace('"', '', json_encode($resolvedValue)); |
40
|
|
|
} |
41
|
|
|
|
42
|
9 |
|
public function build($config) |
43
|
|
|
{ |
44
|
|
|
$config |
45
|
9 |
|
->addField('name', new NonNullType(TypeMap::TYPE_STRING)) |
46
|
9 |
|
->addField('description', TypeMap::TYPE_STRING) |
47
|
9 |
|
->addField('isDeprecated', new NonNullType(TypeMap::TYPE_BOOLEAN)) |
48
|
9 |
|
->addField('deprecationReason', TypeMap::TYPE_STRING) |
49
|
9 |
|
->addField(new Field([ |
50
|
9 |
|
'name' => 'type', |
51
|
9 |
|
'type' => new NonNullType(new QueryType()), |
52
|
9 |
|
'resolve' => [$this, 'resolveType'] |
53
|
9 |
|
])) |
54
|
9 |
|
->addField('defaultValue', [ |
55
|
9 |
|
'type' => TypeMap::TYPE_STRING, |
56
|
9 |
|
'resolve' => [$this, 'resolveDefaultValue'] |
57
|
9 |
|
]); |
58
|
9 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string type name |
62
|
|
|
*/ |
63
|
11 |
|
public function getName() |
64
|
|
|
{ |
65
|
11 |
|
return '__InputValue'; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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: