|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoeSangue\GraphQL\Query; |
|
4
|
|
|
|
|
5
|
|
|
use GraphQL; |
|
6
|
|
|
use DoeSangue\Models\User; |
|
7
|
|
|
use GraphQL\Type\Definition\Type; |
|
8
|
|
|
use Folklore\GraphQL\Support\Query; |
|
9
|
|
|
|
|
10
|
|
|
class DonorsQuery extends Query |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
protected $attributes = [ |
|
14
|
|
|
'name' => 'donors' |
|
15
|
|
|
]; |
|
16
|
|
|
|
|
17
|
|
|
public function type() |
|
18
|
|
|
{ |
|
19
|
|
|
return Type::listOf(GraphQL::type('Donor')); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function args() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
'first_name' => ['name' => 'firs_tname', 'type' => Type::string()], |
|
26
|
|
|
'last_name' => ['name' => 'last_name', 'type' => Type::string()], |
|
27
|
|
|
'email' => ['name' => 'email', 'type' => Type::string()], |
|
28
|
|
|
'username' => ['name' => 'username', 'type' => Type::string()], |
|
29
|
|
|
'phone' => ['name' => 'phone', 'type' => Type::string()], |
|
30
|
|
|
'country_code' => ['name' => 'country_code', 'type' => Type::string()], |
|
31
|
|
|
'bio' => ['name' => 'bio', 'type' => Type::string()], |
|
32
|
|
|
'birthdate' => ['name' => 'birthdate', 'type' => Type::string()], |
|
33
|
|
|
'active' => ['name' => 'active', 'type' => Type::string()], |
|
34
|
|
|
'password' => ['name' => 'password', 'type' => Type::string()], |
|
35
|
|
|
'blood_type_id' => ['name' => 'blood_type_id', 'type' => Type::string()], |
|
36
|
|
|
'first' => ['name' => 'first', 'type' => Type::int()], |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function resolve($root,$args) |
|
41
|
|
|
{ |
|
42
|
|
|
$donor = new User; |
|
43
|
|
|
|
|
44
|
|
|
// Limit |
|
45
|
|
|
if (isset($args['first'])) { |
|
46
|
|
|
$donor = $donor->limit($args['first'])->latest('id'); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (isset($args['id'])) |
|
50
|
|
|
{ |
|
51
|
|
|
$donor = $donor->where('id', $args['id']); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (isset($args['email'])) |
|
55
|
|
|
{ |
|
56
|
|
|
$donor = $donor->where('email', $args['email']); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $donor->get(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: