1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Type; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\GraphQL; |
6
|
|
|
use Digia\GraphQL\Language\DirectiveLocationEnum; |
7
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
8
|
|
|
use function Digia\GraphQL\Type\GraphQLBoolean; |
9
|
|
|
use function Digia\GraphQL\Type\GraphQLDirective; |
10
|
|
|
use function Digia\GraphQL\Type\GraphQLNonNull; |
11
|
|
|
use function Digia\GraphQL\Type\GraphQLString; |
12
|
|
|
|
13
|
|
|
class DirectivesProvider extends AbstractServiceProvider |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $provides = [ |
19
|
|
|
GraphQL::INCLUDE_DIRECTIVE, |
20
|
|
|
GraphQL::SKIP_DIRECTIVE, |
21
|
|
|
GraphQL::DEPRECATED_DIRECTIVE, |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritdoc |
26
|
|
|
*/ |
27
|
|
|
public function register() |
28
|
|
|
{ |
29
|
|
|
$this->container->add(GraphQL::INCLUDE_DIRECTIVE, function () { |
30
|
|
|
return GraphQLDirective([ |
31
|
|
|
'name' => 'include', |
32
|
|
|
'description' => |
33
|
|
|
'Directs the executor to include this field or fragment only when ' . |
34
|
|
|
'the `if` argument is true.', |
35
|
|
|
'locations' => [ |
36
|
|
|
DirectiveLocationEnum::FIELD, |
37
|
|
|
DirectiveLocationEnum::FRAGMENT_SPREAD, |
38
|
|
|
DirectiveLocationEnum::INLINE_FRAGMENT, |
39
|
|
|
], |
40
|
|
|
'args' => [ |
41
|
|
|
'if' => [ |
42
|
|
|
'type' => GraphQLNonNull(GraphQLBoolean()), |
43
|
|
|
'description' => 'Included when true.', |
44
|
|
|
], |
45
|
|
|
], |
46
|
|
|
]); |
47
|
|
|
}, true/* $shared */); |
48
|
|
|
|
49
|
|
|
$this->container->add(GraphQL::SKIP_DIRECTIVE, function () { |
50
|
|
|
return GraphQLDirective([ |
51
|
|
|
'name' => 'skip', |
52
|
|
|
'description' => |
53
|
|
|
'Directs the executor to skip this field or fragment when the `if` ' . |
54
|
|
|
'argument is true.', |
55
|
|
|
'locations' => [ |
56
|
|
|
DirectiveLocationEnum::FIELD, |
57
|
|
|
DirectiveLocationEnum::FRAGMENT_SPREAD, |
58
|
|
|
DirectiveLocationEnum::INLINE_FRAGMENT, |
59
|
|
|
], |
60
|
|
|
'args' => [ |
61
|
|
|
'if' => [ |
62
|
|
|
'type' => GraphQLNonNull(GraphQLBoolean()), |
63
|
|
|
'description' => 'Skipped when true.', |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
]); |
67
|
|
|
}, true/* $shared */); |
68
|
|
|
|
69
|
|
|
$this->container->add(GraphQL::DEPRECATED_DIRECTIVE, function () { |
70
|
|
|
return GraphQLDirective([ |
71
|
|
|
'name' => 'deprecated', |
72
|
|
|
'description' => 'Marks an element of a GraphQL schema as no longer supported.', |
73
|
|
|
'locations' => [ |
74
|
|
|
DirectiveLocationEnum::FIELD_DEFINITION, |
75
|
|
|
DirectiveLocationEnum::ENUM_VALUE, |
76
|
|
|
], |
77
|
|
|
'args' => [ |
78
|
|
|
'reason' => [ |
79
|
|
|
'type' => GraphQLString(), |
80
|
|
|
'description' => |
81
|
|
|
'Explains why this element was deprecated, usually also including a ' . |
82
|
|
|
'suggestion for how to access supported similar data. Formatted ' . |
83
|
|
|
'in [Markdown](https://daringfireball.net/projects/markdown/).', |
84
|
|
|
'defaultValue' => DEFAULT_DEPRECATION_REASON, |
85
|
|
|
], |
86
|
|
|
] |
87
|
|
|
]); |
88
|
|
|
}, true/* $shared */); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|