|
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\Queries; |
|
10
|
|
|
|
|
11
|
|
|
use GraphQL\Type\Definition\Type; |
|
12
|
|
|
use GraphQL\Type\Definition\ObjectType; |
|
13
|
|
|
use App\GraphQL\Kernel\Paginator\PaginatorConfiguration; |
|
14
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class PaginatorQuery |
|
18
|
|
|
* @package App\GraphQL\Queries |
|
19
|
|
|
*/ |
|
20
|
|
|
class PaginatorQuery extends AbstractQuery |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $attributes = [ |
|
26
|
|
|
'name' => 'Paginator query', |
|
27
|
|
|
'description' => 'Returns an info about query', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return ObjectType |
|
32
|
|
|
*/ |
|
33
|
|
|
public function type(): ObjectType |
|
34
|
|
|
{ |
|
35
|
|
|
return \GraphQL::type('Paginator'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param $root |
|
40
|
|
|
* @param array $args |
|
41
|
|
|
* @return array |
|
42
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function resolve($root, array $args = []): array |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$paginator = PaginatorConfiguration::find($args['query']); |
|
47
|
|
|
if ($paginator === null) { |
|
48
|
|
|
throw new NotFoundHttpException('No info about ' . $args['query'] . ' query'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return [ |
|
52
|
|
|
'total_count' => $paginator->getCount(), |
|
53
|
|
|
'pages_count' => $paginator->getPages(), |
|
54
|
|
|
'limit' => $paginator->getLimit(), |
|
55
|
|
|
'skip' => $paginator->getSkip(), |
|
56
|
|
|
'page' => $paginator->getPage(), |
|
57
|
|
|
'per_page' => $paginator->getPerPage(), |
|
58
|
|
|
'is_first_page' => $paginator->getSkip() === 0, |
|
59
|
|
|
'is_last_page' => $paginator->getPage() >= $paginator->getPages(), |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function queryArguments(): array |
|
67
|
|
|
{ |
|
68
|
|
|
return [ |
|
69
|
|
|
'query' => [ |
|
70
|
|
|
'name' => 'query', |
|
71
|
|
|
'type' => Type::nonNull(Type::string()), |
|
72
|
|
|
], |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.