Completed
Pull Request — master (#204)
by Ryan
11:34
created

Issue90Schema   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 51
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2015–2018 Alexandr Viniychuk <http://youshido.com>.
4
 * Copyright (c) 2015–2018 Portey Vasil <https://github.com/portey>.
5
 * Copyright (c) 2018 Ryan Parman <https://github.com/skyzyx>.
6
 * Copyright (c) 2018 Ashley Hutson <https://github.com/asheliahut>.
7
 * Copyright (c) 2015–2018 Contributors.
8
 *
9
 * http://opensource.org/licenses/MIT
10
 */
11
12
declare(strict_types=1);
13
14
namespace Youshido\Tests\Issues\Issue90;
15
16
use Youshido\GraphQL\Config\Schema\SchemaConfig;
17
use Youshido\GraphQL\Schema\AbstractSchema;
18
use Youshido\GraphQL\Type\Object\ObjectType;
19
use Youshido\GraphQL\Type\Scalar\DateTimeType;
20
21
class Issue90Schema extends AbstractSchema
22
{
23
    public function build(SchemaConfig $config): void
24
    {
25
        $config->setQuery(
26
            new ObjectType([
27
                'name'   => 'QueryType',
28
                'fields' => [
29
                    'echo' => [
30
                        'type' => new DateTimeType('Y-m-d H:ia'),
31
                        'args' => [
32
                            'date' => new DateTimeType('Y-m-d H:ia'),
33
                        ],
34
                        'resolve' => static function ($value, $args, $info) {
35
                            if (isset($args['date'])) {
36
                                return $args['date'];
37
                            }
38
                        },
39
                    ],
40
                ],
41
            ])
42
        );
43
44
        $config->setMutation(
45
            new ObjectType([
46
                'name'   => 'MutationType',
47
                'fields' => [
48
                    'echo' => [
49
                        'type' => new DateTimeType('Y-m-d H:ia'),
50
                        'args' => [
51
                            'date' => new DateTimeType('Y-m-d H:ia'),
52
                        ],
53
                        'resolve' => static function ($value, $args, $info) {
54
                            if (isset($args['date'])) {
55
                                return $args['date'];
56
                            }
57
                        },
58
                    ],
59
                ],
60
            ])
61
        );
62
    }
63
}
64