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\GraphQL\Serializers\UserSerializer; |
12
|
|
|
use App\GraphQL\Types\AuthUserType; |
13
|
|
|
use App\Models\User; |
14
|
|
|
use GraphQL\Type\Definition\Type; |
15
|
|
|
use Illuminate\Contracts\Validation\Validator; |
16
|
|
|
use Illuminate\Support\Arr; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class RegistrationMutation |
20
|
|
|
* @package App\GraphQL\Mutations |
21
|
|
|
*/ |
22
|
|
|
class RegistrationMutation extends AbstractMutation |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $attributes = [ |
28
|
|
|
'name' => 'register', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
public function args() |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'name' => [ |
38
|
|
|
'type' => Type::nonNull(Type::string()), |
39
|
|
|
'description' => 'User name', |
40
|
|
|
], |
41
|
|
|
'email' => [ |
42
|
|
|
'type' => Type::nonNull(Type::string()), |
43
|
|
|
'description' => 'User email', |
44
|
|
|
], |
45
|
|
|
'password' => [ |
46
|
|
|
'type' => Type::nonNull(Type::string()), |
47
|
|
|
'description' => 'User password', |
48
|
|
|
], |
49
|
|
|
'password_confirmation' => [ |
50
|
|
|
'type' => Type::nonNull(Type::string()), |
51
|
|
|
'description' => 'User password confirmation', |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return \GraphQL\Type\Definition\ObjectType|mixed|null |
58
|
|
|
*/ |
59
|
|
|
public function type() |
60
|
|
|
{ |
61
|
|
|
return \GraphQL::type(AuthUserType::getName()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function rules(): array |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
'name' => [ |
71
|
|
|
'min:2', |
72
|
|
|
'unique:users,name' |
73
|
|
|
], |
74
|
|
|
'email' => [ |
75
|
|
|
'email', |
76
|
|
|
'unique:users,email' |
77
|
|
|
], |
78
|
|
|
'password' => [ |
79
|
|
|
'min:2', |
80
|
|
|
'max:100', |
81
|
|
|
'confirmed' |
82
|
|
|
] |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param $root |
88
|
|
|
* @param $args |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function resolve($root, $args) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$user = User::create(Arr::only($args, ['name', 'email', 'password'])); |
94
|
|
|
|
95
|
|
|
return UserSerializer::serialize($user); |
96
|
|
|
} |
97
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.