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\Types; |
10
|
|
|
|
11
|
|
|
use App\Models\DocsPage; |
12
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
13
|
|
|
use GraphQL\Type\Definition\Type; |
14
|
|
|
use App\GraphQL\Serializers\DocsPageSerializer; |
15
|
|
|
use App\GraphQL\Queries\Support\WhereInSelection; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class DocsType. |
19
|
|
|
*/ |
20
|
|
|
class DocsType extends AbstractType |
21
|
|
|
{ |
22
|
|
|
use WhereInSelection; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $attributes = [ |
28
|
|
|
'name' => 'Docs', |
29
|
|
|
'description' => 'Documentation repository', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
public function fields(): array |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
'id' => [ |
39
|
|
|
'type' => Type::nonNull(Type::id()), |
40
|
|
|
'description' => 'Docs identifier', |
41
|
|
|
], |
42
|
|
|
'project' => [ |
43
|
|
|
'type' => Type::nonNull(Type::string()), |
44
|
|
|
'description' => 'Docs project name', |
45
|
|
|
], |
46
|
|
|
'pages' => [ |
47
|
|
|
'args' => $this->argumentsWithWhereIn([ |
48
|
|
|
'slug' => [ |
49
|
|
|
'type' => Type::string(), |
50
|
|
|
'description' => 'Docs page slug', |
51
|
|
|
], |
52
|
|
|
]), |
53
|
|
|
'type' => Type::listOf(\GraphQL::type(DocsPageType::getName())), |
54
|
|
|
'description' => '', |
55
|
|
|
], |
56
|
|
|
'title' => [ |
57
|
|
|
'type' => Type::nonNull(Type::string()), |
58
|
|
|
'description' => '', |
59
|
|
|
], |
60
|
|
|
'image' => [ |
61
|
|
|
'type' => Type::nonNull(Type::string()), |
62
|
|
|
'description' => '', |
63
|
|
|
], |
64
|
|
|
'version' => [ |
65
|
|
|
'type' => Type::nonNull(Type::string()), |
66
|
|
|
'description' => '', |
67
|
|
|
], |
68
|
|
|
'description' => [ |
69
|
|
|
'type' => Type::nonNull(Type::string()), |
70
|
|
|
'description' => '', |
71
|
|
|
], |
72
|
|
|
'created_at' => [ |
73
|
|
|
'type' => Type::nonNull(Type::string()), |
74
|
|
|
'description' => '', |
75
|
|
|
], |
76
|
|
|
'updated_at' => [ |
77
|
|
|
'type' => Type::nonNull(Type::string()), |
78
|
|
|
'description' => '', |
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param $root |
85
|
|
|
* @param array $args |
86
|
|
|
* @return \Illuminate\Support\Collection |
87
|
|
|
*/ |
88
|
|
|
public function resolvePagesField(array $root, array $args) |
89
|
|
|
{ |
90
|
|
|
$query = DocsPage::whereDocsId($root['id']); |
91
|
|
|
|
92
|
|
|
$query = $this->queryWithWhereIn($query, $args); |
93
|
|
|
|
94
|
|
|
$this->whenExists($args, 'slug', function (string $slug) use ($query) { |
95
|
|
|
return $query->where('slug', $slug); |
96
|
|
|
}); |
97
|
|
|
|
98
|
|
|
return DocsPageSerializer::collection($query->get()); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.