Completed
Push — master ( 29ef50...718f9d )
by Alexandr
03:01
created

Issue109Schema   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 7
dl 0
loc 63
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 58 4
1
<?php
2
namespace Youshido\Tests\Issues\Issue109;
3
4
use Youshido\GraphQL\Config\Schema\SchemaConfig;
5
use Youshido\GraphQL\Execution\ResolveInfo;
6
use Youshido\GraphQL\Schema\AbstractSchema;
7
use Youshido\GraphQL\Type\ListType\ListType;
8
use Youshido\GraphQL\Type\Object\ObjectType;
9
use Youshido\GraphQL\Type\Scalar\IntType;
10
11
class Issue109Schema extends AbstractSchema
12
{
13
14
    public function build(SchemaConfig $config)
15
    {
16
        $config->setQuery(
17
            new ObjectType([
18
                'name'   => 'RootQueryType',
19
                'fields' => [
20
                    'latestPost' => [
21
                        'type'    => new ObjectType([
22
                            'name'   => 'Post',
23
                            'fields' => [
24
                                'id'       => [
25
                                    'type' => new IntType(),
26
                                    'args' => [
27
                                        'comment_id' => new IntType()
28
                                    ]
29
                                ],
30
                                'comments' => [
31
                                    'type' => new ListType(new ObjectType([
32
                                        'name'   => 'Comment',
33
                                        'fields' => [
34
                                            'comment_id' => new IntType()
35
                                        ]
36
                                    ])),
37
                                    'args' => [
38
                                        'comment_id' => new IntType()
39
                                    ]
40
                                ]
41
                            ]
42
                        ]),
43
                        'resolve' => function ($source, array $args, ResolveInfo $info) {
44
                            $internalArgs = [
45
                                'comment_id' => 200
46
                            ];
47
                            foreach ($info->getFieldASTList() as $field) {
48
                                if ($field->getName() == 'comments' && $field->hasArguments()) {
49
                                    $internalArgs = $field->getKeyValueArguments();
50
                                }
51
                            }
52
53
                            return [
54
                                "id"       => 1,
55
                                "title"    => "New approach in API has been revealed",
56
                                "summary"  => "In two words - GraphQL Rocks!",
57
                                "comments" => [
58
                                    [
59
                                        "comment_id" => $internalArgs['comment_id']
60
                                    ]
61
                                ]
62
                            ];
63
                        },
64
                        'args'    => [
65
                            'id' => new IntType()
66
                        ]
67
                    ]
68
                ]
69
            ])
70
        );
71
    }
72
73
}