|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of laravel.ru 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\Queries; |
|
10
|
|
|
|
|
11
|
|
|
use App\GraphQL\Types\SearchResultType; |
|
12
|
|
|
use GraphQL\Type\Definition\ListOfType; |
|
13
|
|
|
use GraphQL\Type\Definition\Type; |
|
14
|
|
|
use Illuminate\Support\Collection; |
|
15
|
|
|
use Service\SearchService\SearchRepositoryInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class SearchQuery |
|
19
|
|
|
* @package App\GraphQL\Queries |
|
20
|
|
|
*/ |
|
21
|
|
|
class SearchQuery extends AbstractQuery |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $attributes = [ |
|
27
|
|
|
'name' => 'Article list query', |
|
28
|
|
|
'description' => 'Returns a list of available articles', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return ListOfType |
|
33
|
|
|
*/ |
|
34
|
|
|
public function type(): ListOfType |
|
35
|
|
|
{ |
|
36
|
|
|
return Type::listOf(\GraphQL::type(SearchResultType::getName())); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param $root |
|
41
|
|
|
* @param array $args |
|
42
|
|
|
* @return Collection |
|
43
|
|
|
*/ |
|
44
|
|
|
public function resolve($root, array $args = []): Collection |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
// TODO Query can be empty |
|
47
|
|
|
return app(SearchRepositoryInterface::class) |
|
48
|
|
|
->getItems($args['query'], $args['type'] ?? null); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function queryArguments(): array |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
|
|
'type' => [ |
|
58
|
|
|
'type' => Type::string(), |
|
59
|
|
|
'description' => 'Can be one of docs, articles', |
|
60
|
|
|
], |
|
61
|
|
|
'query' => [ |
|
62
|
|
|
'type' => Type::nonNull(Type::string()), |
|
63
|
|
|
'description' => '', |
|
64
|
|
|
], |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.