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\Type; |
13
|
|
|
use App\GraphQL\Feature\SelectById; |
14
|
|
|
use App\GraphQL\Serializers\DocsPageSerializer; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class DocsType. |
18
|
|
|
*/ |
19
|
|
|
class DocsType extends AbstractType |
20
|
|
|
{ |
21
|
|
|
use SelectById; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $attributes = [ |
27
|
|
|
'name' => 'Docs', |
28
|
|
|
'description' => 'Documentation repository', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
public function typeFields(): array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'id' => [ |
38
|
|
|
'type' => Type::nonNull(Type::id()), |
39
|
|
|
'description' => 'Docs identifier', |
40
|
|
|
], |
41
|
|
|
'project' => [ |
42
|
|
|
'type' => Type::nonNull(Type::string()), |
43
|
|
|
'description' => 'Docs project name', |
44
|
|
|
], |
45
|
|
|
'pages' => [ |
46
|
|
|
'args' => $this->extendArguments([ |
47
|
|
|
'slug' => [ |
48
|
|
|
'type' => Type::string(), |
49
|
|
|
'description' => 'Docs page slug', |
50
|
|
|
], |
51
|
|
|
]), |
52
|
|
|
'type' => Type::listOf(\GraphQL::type('DocsPage')), |
53
|
|
|
'description' => '', |
54
|
|
|
], |
55
|
|
|
'title' => [ |
56
|
|
|
'type' => Type::nonNull(Type::string()), |
57
|
|
|
'description' => '', |
58
|
|
|
], |
59
|
|
|
'image' => [ |
60
|
|
|
'type' => Type::nonNull(Type::string()), |
61
|
|
|
'description' => '', |
62
|
|
|
], |
63
|
|
|
'version' => [ |
64
|
|
|
'type' => Type::nonNull(Type::string()), |
65
|
|
|
'description' => '', |
66
|
|
|
], |
67
|
|
|
'description' => [ |
68
|
|
|
'type' => Type::nonNull(Type::string()), |
69
|
|
|
'description' => '', |
70
|
|
|
], |
71
|
|
|
'created_at' => [ |
72
|
|
|
'type' => Type::nonNull(Type::string()), |
73
|
|
|
'description' => '', |
74
|
|
|
], |
75
|
|
|
'updated_at' => [ |
76
|
|
|
'type' => Type::nonNull(Type::string()), |
77
|
|
|
'description' => '', |
78
|
|
|
], |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $root |
84
|
|
|
* @param array $args |
85
|
|
|
* @return \Illuminate\Support\Collection |
86
|
|
|
*/ |
87
|
|
|
public function resolvePagesField(array $root, array $args) |
88
|
|
|
{ |
89
|
|
|
$query = DocsPage::whereDocsId($root['id']); |
90
|
|
|
|
91
|
|
|
$query = $this->extendQuery($query, $args); |
92
|
|
|
|
93
|
|
|
$this->whenExists($args, 'slug', function (string $slug) use ($query) { |
94
|
|
|
return $query->where('slug', $slug); |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
return DocsPageSerializer::collection($query->get()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|