init
This commit is contained in:
74
GraphQLSchemaPagination.php
Normal file
74
GraphQLSchemaPagination.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace dominion\api;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use dominion\api\GraphQLPagination;
|
||||
|
||||
class GraphQLSchemaPagination extends ObjectType
|
||||
{
|
||||
public $isPagination = false;
|
||||
public function getCustomFields()
|
||||
{
|
||||
return [
|
||||
'totalCount' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Количество элементов',
|
||||
],
|
||||
'pageCount' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Количество страниц',
|
||||
],
|
||||
'currentPage' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Текущая страница',
|
||||
],
|
||||
'perPage' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Элементов на странице',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getCustomResolve($root, $args)
|
||||
{
|
||||
$model = new GraphQLPagination;
|
||||
$model->parentRoot = $root;
|
||||
$model->page = isset($args['page']) && $args['page'] > 1 ? $args['page'] : 1;
|
||||
$model->perPage = isset($args['perPage']) && $args['perPage'] > 0 ? $args['perPage'] : 50;
|
||||
$model->offset = isset($args['offset']) && $args['offset'] > 0 ? $args['offset'] : 0;
|
||||
$model->addArgs = isset($args['addArgs']) ? (array)$args['addArgs'] : [];
|
||||
|
||||
return $model;//['totalCount' =>0, 'pageCount' => 0, 'currentPage' => 0, 'perPage'=> 0, 'data' => []];
|
||||
}
|
||||
public function getCustomArgs()
|
||||
{
|
||||
return [
|
||||
'page' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Номер страницы (по умолчанию 1)',
|
||||
],
|
||||
'perPage' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Количество элементов на странице (по умолчанию 50)',
|
||||
],
|
||||
'offset' => [
|
||||
'type' => Type::int(),
|
||||
'description' => 'Смещение от начала выборки',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function resultArguments($args)
|
||||
{
|
||||
$output = [];
|
||||
foreach ($args as $key => $value)
|
||||
{
|
||||
$output[$key] = json_decode($value, true);
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user