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\AbstractField; |
11
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
12
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
13
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
14
|
|
|
|
15
|
|
|
class FieldType extends AbstractObjectType |
16
|
|
|
{ |
17
|
|
|
|
18
|
3 |
|
public static function resolveType(AbstractField $value) |
19
|
|
|
{ |
20
|
3 |
|
return $value->getType(); |
21
|
|
|
} |
22
|
|
|
|
23
|
2 |
|
public static function resolveArgs(AbstractField $value) |
24
|
|
|
{ |
25
|
2 |
|
if ($value->getConfig()->hasArguments()) { |
26
|
2 |
|
return $value->getConfig()->getArguments(); |
27
|
|
|
} |
28
|
|
|
|
29
|
2 |
|
return []; |
30
|
|
|
} |
31
|
|
|
|
32
|
6 |
|
public function build($config) |
33
|
|
|
{ |
34
|
|
|
$config |
35
|
6 |
|
->addField('name', TypeMap::TYPE_STRING) |
36
|
6 |
|
->addField('description', TypeMap::TYPE_STRING) |
37
|
6 |
|
->addField('isDeprecated', TypeMap::TYPE_BOOLEAN) |
38
|
6 |
|
->addField('deprecationReason', TypeMap::TYPE_STRING) |
39
|
6 |
|
->addField('type', [ |
40
|
6 |
|
'type' => new QueryType(), |
41
|
6 |
|
'resolve' => [get_class($this), 'resolveType'], |
42
|
|
|
]) |
43
|
6 |
|
->addField('args', [ |
44
|
6 |
|
'type' => new ListType(new InputValueType()), |
45
|
6 |
|
'resolve' => [get_class($this), 'resolveArgs'], |
46
|
|
|
]); |
47
|
6 |
|
} |
48
|
|
|
|
49
|
4 |
|
public function isValidValue($value) |
50
|
|
|
{ |
51
|
4 |
|
return $value instanceof AbstractField; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return String type name |
56
|
|
|
*/ |
57
|
7 |
|
public function getName() |
58
|
|
|
{ |
59
|
7 |
|
return '__Field'; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|