Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\GraphQL\Query;
- use App\User;
- use GraphQL\Type\Definition\Type;
- use Rebing\GraphQL\Support\Facades\GraphQL;
- use Rebing\GraphQL\Support\Query;
- use Rebing\GraphQL\Support\SelectFields;
- class UsersQuery extends Query
- {
- protected $attributes = [
- 'name' => 'Users Query',
- 'description' => 'A query of users'
- ];
- public function type()
- {
- // result of query with pagination laravel
- return GraphQL::paginate('users');
- }
- // arguments to filter query
- public function args()
- {
- return [
- 'id' => [
- 'name' => 'id',
- 'type' => Type::int()
- ],
- 'email' => [
- 'name' => 'email',
- 'type' => Type::string()
- ]
- ];
- }
- public function resolve($root, $args, SelectFields $fields)
- {
- $where = function ($query) use ($args) {
- if (isset($args['id'])) {
- $query->where('id',$args['id']);
- }
- if (isset($args['email'])) {
- $query->where('email',$args['email']);
- }
- };
- $user = User::with(array_keys($fields->getRelations()))
- ->where($where)
- ->select($fields->getSelect())
- ->paginate();
- return $user;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement