|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Date: 16.12.15 |
|
4
|
|
|
* |
|
5
|
|
|
* @author Portey Vasil <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Youshido\GraphQL\Introspection; |
|
9
|
|
|
|
|
10
|
|
|
use Youshido\GraphQL\Config\Directive\DirectiveConfig; |
|
11
|
|
|
use Youshido\GraphQL\Directive\Directive; |
|
12
|
|
|
use Youshido\GraphQL\Directive\DirectiveInterface; |
|
13
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
|
14
|
|
|
use Youshido\GraphQL\Type\NonNullType; |
|
15
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
|
16
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
|
17
|
|
|
|
|
18
|
|
|
class DirectiveType extends AbstractObjectType |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return String type name |
|
23
|
|
|
*/ |
|
24
|
9 |
|
public function getName() |
|
25
|
|
|
{ |
|
26
|
9 |
|
return '__Directive'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function resolveArgs(DirectiveInterface $value) |
|
30
|
|
|
{ |
|
31
|
|
|
if ($value->hasArguments()) { |
|
32
|
|
|
return $value->getArguments(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return []; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param DirectiveInterface|Directive $value |
|
40
|
|
|
* |
|
41
|
|
|
* @return mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
public function resolveLocations(DirectiveInterface $value) |
|
44
|
|
|
{ |
|
45
|
|
|
/** @var DirectiveConfig $directiveConfig */ |
|
46
|
|
|
$directiveConfig = $value->getConfig(); |
|
47
|
|
|
|
|
48
|
|
|
$locations = $directiveConfig->getLocations(); |
|
49
|
|
|
|
|
50
|
|
|
return $locations; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
public function build($config) |
|
54
|
|
|
{ |
|
55
|
|
|
$config |
|
56
|
6 |
|
->addField('name', new NonNullType(TypeMap::TYPE_STRING)) |
|
57
|
6 |
|
->addField('description', TypeMap::TYPE_STRING) |
|
58
|
6 |
|
->addField('args', [ |
|
59
|
6 |
|
'type' => new NonNullType(new ListType(new NonNullType(new InputValueType()))), |
|
60
|
6 |
|
'resolve' => [$this, 'resolveArgs'], |
|
61
|
|
|
]) |
|
62
|
6 |
|
->addField('locations',[ |
|
63
|
6 |
|
'type' => new NonNullType(new ListType(new NonNullType(new DirectiveLocationType()))), |
|
64
|
6 |
|
'resolve' => [$this, 'resolveLocations'], |
|
65
|
|
|
]); |
|
66
|
6 |
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|