| @@ 25-76 (lines=52) @@ | ||
| 22 | /** |
|
| 23 | * Class TagsQuery. |
|
| 24 | */ |
|
| 25 | class TagsQuery extends Query |
|
| 26 | { |
|
| 27 | use QueryLimit; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @var array |
|
| 31 | */ |
|
| 32 | protected $attributes = [ |
|
| 33 | 'name' => 'Tags list query', |
|
| 34 | 'description' => 'Returns a list of available tags', |
|
| 35 | ]; |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return ListOfType |
|
| 39 | */ |
|
| 40 | public function type(): ListOfType |
|
| 41 | { |
|
| 42 | return Type::listOf(\GraphQL::type(TagType::getName())); |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @return array |
|
| 47 | */ |
|
| 48 | public function args(): array |
|
| 49 | { |
|
| 50 | return $this->argumentsWithLimit([ |
|
| 51 | 'id' => [ |
|
| 52 | 'type' => Type::id(), |
|
| 53 | 'description' => 'Tag identifier', |
|
| 54 | ], |
|
| 55 | ]); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @param $root |
|
| 60 | * @param array $args |
|
| 61 | * @return Collection |
|
| 62 | */ |
|
| 63 | public function resolve($root, array $args = []): Collection |
|
| 64 | { |
|
| 65 | $query = Tag::query(); |
|
| 66 | ||
| 67 | $query = $this->paginate($query, $args); |
|
| 68 | ||
| 69 | foreach ($args as $field => $value) { |
|
| 70 | $query = $query->where($field, $value); |
|
| 71 | } |
|
| 72 | ||
| 73 | return TagSerializer::collection($query->get()); |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||
| @@ 25-76 (lines=52) @@ | ||
| 22 | /** |
|
| 23 | * Class UsersQuery. |
|
| 24 | */ |
|
| 25 | class UsersQuery extends Query |
|
| 26 | { |
|
| 27 | use QueryLimit; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @var array |
|
| 31 | */ |
|
| 32 | protected $attributes = [ |
|
| 33 | 'name' => 'Users list query', |
|
| 34 | 'description' => 'Returns a list of users', |
|
| 35 | ]; |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return ListOfType |
|
| 39 | */ |
|
| 40 | public function type(): ListOfType |
|
| 41 | { |
|
| 42 | return Type::listOf(\GraphQL::type(UserType::getName())); |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @return array |
|
| 47 | */ |
|
| 48 | public function args(): array |
|
| 49 | { |
|
| 50 | return $this->argumentsWithLimit([ |
|
| 51 | 'id' => [ |
|
| 52 | 'type' => Type::id(), |
|
| 53 | 'description' => 'User identifier', |
|
| 54 | ], |
|
| 55 | ]); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @param $root |
|
| 60 | * @param array $args |
|
| 61 | * @return Collection |
|
| 62 | */ |
|
| 63 | public function resolve($root, array $args = []): Collection |
|
| 64 | { |
|
| 65 | $query = User::query(); |
|
| 66 | ||
| 67 | $query = $this->paginate($query, $args); |
|
| 68 | ||
| 69 | foreach ($args as $field => $value) { |
|
| 70 | $query = $query->where($field, $value); |
|
| 71 | } |
|
| 72 | ||
| 73 | return UserSerializer::collection($query->get()); |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||
| @@ 25-76 (lines=52) @@ | ||
| 22 | /** |
|
| 23 | * Class TipsQuery. |
|
| 24 | */ |
|
| 25 | class TipsQuery extends Query |
|
| 26 | { |
|
| 27 | use QueryLimit; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @var array |
|
| 31 | */ |
|
| 32 | protected $attributes = [ |
|
| 33 | 'name' => 'Tips list query', |
|
| 34 | 'description' => 'Returns a list of available tips', |
|
| 35 | ]; |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @return ListOfType |
|
| 39 | */ |
|
| 40 | public function type(): ListOfType |
|
| 41 | { |
|
| 42 | return Type::listOf(\GraphQL::type(TipType::getName())); |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @return array |
|
| 47 | */ |
|
| 48 | public function args(): array |
|
| 49 | { |
|
| 50 | return $this->argumentsWithLimit([ |
|
| 51 | 'id' => [ |
|
| 52 | 'type' => Type::id(), |
|
| 53 | 'description' => 'Tip identifier', |
|
| 54 | ], |
|
| 55 | ]); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @param $root |
|
| 60 | * @param array $args |
|
| 61 | * @return Collection |
|
| 62 | */ |
|
| 63 | public function resolve($root, array $args = []): Collection |
|
| 64 | { |
|
| 65 | /** @var Builder $query */ |
|
| 66 | $query = Tip::with('likes', 'dislikes', 'user'); |
|
| 67 | ||
| 68 | $query = $this->paginate($query, $args); |
|
| 69 | ||
| 70 | foreach ($args as $field => $value) { |
|
| 71 | $query = $query->where($field, $value); |
|
| 72 | } |
|
| 73 | ||
| 74 | return TipSerializer::collection($query->get()); |
|
| 75 | } |
|
| 76 | } |
|
| 77 | ||