UsersQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A queryArguments() 0 4 1
A resolve() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace App\GraphQL\Queries;
11
12
use App\Models\User;
13
use GraphQL\Type\Definition\Type;
14
use App\GraphQL\Feature\Paginator;
15
use App\GraphQL\Feature\SelectById;
16
use GraphQL\Type\Definition\ListOfType;
17
use App\GraphQL\Serializers\UserSerializer;
18
19
/**
20
 * Class UsersQuery.
21
 */
22
class UsersQuery extends AbstractQuery
23
{
24
    use Paginator;
25
    use SelectById;
26
27
    /**
28
     * @var array
29
     */
30
    protected $attributes = [
31
        'name'        => 'Users list query',
32
        'description' => 'Returns a list of users',
33
    ];
34
35
    /**
36
     * @return ListOfType
37
     */
38
    public function type(): ListOfType
39
    {
40
        return Type::listOf(\GraphQL::type('User'));
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    protected function queryArguments(): array
47
    {
48
        return [];
49
    }
50
51
    /**
52
     * @param        $root
53
     * @param  array $args
54
     * @return \Traversable
55
     */
56
    public function resolve($root, array $args = []): \Traversable
57
    {
58
        $query = $this->queryFor(User::class, $args);
59
60
        return $this->paginate($query, $query->count())
61
            ->withArgs($args)
62
            ->use(UserSerializer::class)
63
            ->as('users');
64
    }
65
}
66