Completed
Pull Request — master (#167)
by Sebastian
03:01
created

CategoriesField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
A resolve() 0 19 2
1
<?php
2
/**
3
 * This file is a part of GraphQL project.
4
 *
5
 * @author Alexandr Viniychuk <[email protected]>
6
 * created: 4/24/17 11:42 PM
7
 */
8
9
namespace Examples\BookStore\Schema\Field;
10
11
12
use Examples\BookStore\Schema\Type\CategoryType;
13
use Youshido\GraphQL\Execution\DeferredResolver;
14
use Youshido\GraphQL\Execution\ResolveInfo;
15
use Youshido\GraphQL\Field\AbstractField;
16
use Youshido\GraphQL\Type\ListType\ListType;
17
18
class CategoriesField extends AbstractField
19
{
20
    public function getType()
21
    {
22
        return new ListType(new CategoryType());
23
    }
24
25
    public function resolve($value, array $args, ResolveInfo $info)
26
    {
27
        return new DeferredResolver(function () use ($value) {
28
            $id = empty($value['id']) ? "1" : $value['id'] . ".1";
29
30
            return [
31
                'id'       => $id,
32
                'title'    => 'Category ' . $id,
33
                'authors'  => [
34
                    [
35
                        'id'        => 'author1',
36
                        'firstName' => 'John',
37
                        'lastName'  => 'Doe',
38
                    ],
39
                ],
40
                'children' => [],
41
            ];
42
        });
43
    }
44
}