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
|
|
|
|
10
|
|
|
namespace App\GraphQL\Queries; |
11
|
|
|
|
12
|
|
|
use App\GraphQL\Serializers\DocsSerializer; |
13
|
|
|
use App\Models\Docs; |
14
|
|
|
use App\GraphQL\Types\DocsType; |
15
|
|
|
use GraphQL\Type\Definition\Type; |
16
|
|
|
use Illuminate\Support\Collection; |
17
|
|
|
use Folklore\GraphQL\Support\Query; |
18
|
|
|
use GraphQL\Type\Definition\ListOfType; |
19
|
|
|
use App\GraphQL\Queries\Support\QueryLimit; |
20
|
|
|
use App\GraphQL\Serializers\ArticleSerializer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class DocsQuery. |
24
|
|
|
*/ |
25
|
|
|
class DocsQuery extends Query |
26
|
|
|
{ |
27
|
|
|
use QueryLimit; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $attributes = [ |
33
|
|
|
'name' => 'Docs list query', |
34
|
|
|
'description' => 'Returns a list of available documentation repositories', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return ListOfType |
39
|
|
|
*/ |
40
|
|
|
public function type(): ListOfType |
41
|
|
|
{ |
42
|
|
|
return Type::listOf(\GraphQL::type(DocsType::getName())); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function args(): array |
49
|
|
|
{ |
50
|
|
|
return $this->argumentsWithLimit([]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $root |
55
|
|
|
* @param array $args |
56
|
|
|
* @return Collection |
57
|
|
|
*/ |
58
|
|
|
public function resolve($root, array $args = []): Collection |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$query = Docs::with('pages'); |
61
|
|
|
|
62
|
|
|
$query = $this->paginate($query, $args); |
|
|
|
|
63
|
|
|
|
64
|
|
|
foreach ($args as $field => $value) { |
65
|
|
|
$query = $query->where($field, $value); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return DocsSerializer::collection($query->get()); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.