1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Date: 03.12.15 |
4
|
|
|
* |
5
|
|
|
* @author Portey Vasil <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL\Definition; |
9
|
|
|
|
10
|
|
|
use Youshido\GraphQL\Schema; |
11
|
|
|
use Youshido\GraphQL\Type\Config\TypeConfigInterface; |
12
|
|
|
use Youshido\GraphQL\Type\Field\Field; |
13
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
14
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
15
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
16
|
|
|
|
17
|
|
|
class QueryType extends AbstractObjectType |
18
|
|
|
{ |
19
|
|
|
|
20
|
6 |
|
protected function build(TypeConfigInterface $config) |
21
|
|
|
{ |
22
|
|
|
$config |
23
|
6 |
|
->addField('name', TypeMap::TYPE_STRING) |
24
|
6 |
|
->addField('kind', TypeMap::TYPE_STRING) |
25
|
6 |
|
->addField('description', TypeMap::TYPE_STRING) |
26
|
6 |
|
->addField('ofType', new QueryListType(), [ |
27
|
|
|
'resolve' => function () { |
28
|
2 |
|
return []; |
29
|
|
|
} |
30
|
6 |
|
]) |
31
|
6 |
|
->addField('inputFields', new InputValueListType()) |
32
|
6 |
|
->addField('enumValues', new EnumValueListType()) |
33
|
6 |
|
->addField('fields', new FieldListType()) |
34
|
6 |
|
->addField('interfaces', new InterfaceListType()) |
35
|
6 |
|
->addField('possibleTypes', new ListType(new QueryType()), [ |
36
|
2 |
|
'resolve' => function($value, $args) { |
|
|
|
|
37
|
2 |
|
if ($value && in_array($value->getKind(), [TypeMap::KIND_INTERFACE, TypeMap::KIND_UNION])) { |
38
|
|
|
return $value->getTypes(); |
39
|
|
|
} |
40
|
|
|
|
41
|
2 |
|
return null; |
42
|
|
|
} |
43
|
6 |
|
]); |
44
|
6 |
|
} |
45
|
|
|
|
46
|
3 |
|
public function resolve($value = null, $args = []) |
47
|
|
|
{ |
48
|
|
|
/** @var Schema|Field $value */ |
49
|
3 |
|
if ($value instanceof Schema) { |
50
|
3 |
|
return $value->getQueryType(); |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
return $value->getConfig()->getType(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return String type name |
58
|
|
|
*/ |
59
|
6 |
|
public function getName() |
60
|
|
|
{ |
61
|
6 |
|
return '__Type'; |
62
|
|
|
} |
63
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.