Passed
Pull Request — master (#29)
by Christoffer
02:26
created

DirectivesProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 1

1 Method

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