RegistrationMutation::type()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\GraphQL\Mutations;
10
11
use App\Models\User;
12
use Illuminate\Support\Arr;
13
use GraphQL\Type\Definition\Type;
14
use App\GraphQL\Types\AuthUserType;
15
use App\GraphQL\Serializers\UserSerializer;
16
17
/**
18
 * Class RegistrationMutation.
19
 */
20
class RegistrationMutation extends AbstractMutation
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $attributes = [
26
        'name' => 'register',
27
    ];
28
29
    /**
30
     * @return array
31
     */
32
    public function queryArguments(): array
33
    {
34
        return [
35
            'name'                  => [
36
                'type'        => Type::nonNull(Type::string()),
37
                'description' => 'User name',
38
            ],
39
            'email'                 => [
40
                'type'        => Type::nonNull(Type::string()),
41
                'description' => 'User email',
42
            ],
43
            'password'              => [
44
                'type'        => Type::nonNull(Type::string()),
45
                'description' => 'User password',
46
            ],
47
            'password_confirmation' => [
48
                'type'        => Type::nonNull(Type::string()),
49
                'description' => 'User password confirmation',
50
            ],
51
        ];
52
    }
53
54
    /**
55
     * @return \GraphQL\Type\Definition\ObjectType|mixed|null
56
     */
57
    public function type()
58
    {
59
        return \GraphQL::type('AuthUser');
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function rules(): array
66
    {
67
        return [
68
            'name' => [
69
                'min:2',
70
                'unique:users,name',
71
            ],
72
            'email' => [
73
                'email',
74
                'unique:users,email',
75
            ],
76
            'password' => [
77
                'min:2',
78
                'max:100',
79
                'confirmed',
80
            ],
81
        ];
82
    }
83
84
    /**
85
     * @param $root
86
     * @param $args
87
     * @return array
88
     */
89
    public function resolve($root, $args)
90
    {
91
        $user = User::create(Arr::only($args, ['name', 'email', 'password']));
92
93
        return UserSerializer::serialize($user);
94
    }
95
}
96