namespace App\GraphQL\Query;
use Folklore\GraphQL\Support\Query;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use GraphQL;
use App\User;
class UsersQuery extends Query{
protected $attributes = [
'name' => 'UserQuery',
'description' => 'A query'
];
public function type()
{
return Type::listOf(GraphQL::type('User'));
}
public function args()
{
return [
'id'=>['name'=>'id','type'=>Type::string()],
'userAccount'=>['name'=>'userAccount','type'=>Type::string()],
'userPass'=>['name'=>'userPass','type'=>Type::string()],
'limit'=>['name'=>'limit','type'=>Type::int()]
];
}
public function resolve($root, $args, $context, ResolveInfo $info)
{
$qb = User::orderBy('id', 'desc');
if(isset($args['limit']))
{
$qb->limit($args['limit'])->latest('id');
}
if(isset($args['id']))
{
$qb->where('id',$args['id']);
}
if(isset($args['userAccount']))
{
$qb->where('userAccount',$args['userAccount']);
}
return $qb->get();
}