feat(graphql): add support for IN operators in complex filtering (#1181)

This commit is contained in:
Kyrch
2026-04-19 11:32:35 -03:00
committed by GitHub
parent 00c60c58c4
commit 72b24f2eb6
4 changed files with 28 additions and 22 deletions
@@ -18,4 +18,6 @@ enum ComparisonOperator: string
case GTE = '>='; case GTE = '>=';
case LIKE = 'like'; case LIKE = 'like';
case NOTLIKE = 'not like'; case NOTLIKE = 'not like';
case IN = 'in';
case NOTIN = 'not in';
} }
@@ -64,20 +64,29 @@ class WhereConditionsFilterCriteria extends FilterCriteria
if (filled($fieldName) && filled($value)) { if (filled($fieldName) && filled($value)) {
$field = $this->filterableFields->get($fieldName); $field = $this->filterableFields->get($fieldName);
match ($field->getFilter()->getClause()) { $operator = ComparisonOperator::unstrictCoerce(Arr::get($where, 'operator'));
Clause::WHERE => $builder->where( $value = Arr::first($field->getFilter()->getFilterValues(Arr::wrap($value)));
$field->getColumn(),
ComparisonOperator::unstrictCoerce(Arr::get($where, 'operator'))->value, if ($operator === ComparisonOperator::IN) {
Arr::first($field->getFilter()->getFilterValues(Arr::wrap($value))), $builder->whereIn($field->getColumn(), Arr::wrap($value));
$logical->value } elseif ($operator === ComparisonOperator::NOTIN) {
), $builder->whereNotIn($field->getColumn(), Arr::wrap($value));
Clause::HAVING => $builder->having( } else {
Str::snake($field->getColumn()), match ($field->getFilter()->getClause()) {
ComparisonOperator::unstrictCoerce(Arr::get($where, 'operator'))->value, Clause::WHERE => $builder->where(
Arr::first($field->getFilter()->getFilterValues(Arr::wrap($value))), $field->getColumn(),
$logical->value $operator->value,
), $value,
}; $logical->value
),
Clause::HAVING => $builder->having(
Str::snake($field->getColumn()),
$operator->value,
$value,
$logical->value
),
};
}
} }
$builder->where(function (Builder $builder) use ($where): void { $builder->where(function (Builder $builder) use ($where): void {
@@ -4,11 +4,12 @@ declare(strict_types=1);
namespace App\GraphQL\Schema\Fields\Wiki\Video\VideoScript; namespace App\GraphQL\Schema\Fields\Wiki\Video\VideoScript;
use App\Contracts\GraphQL\Fields\DisplayableField;
use App\GraphQL\Schema\Fields\Field; use App\GraphQL\Schema\Fields\Field;
use App\Models\Wiki\Video\VideoScript; use App\Models\Wiki\Video\VideoScript;
use GraphQL\Type\Definition\Type; use GraphQL\Type\Definition\Type;
class VideoScriptLinkField extends Field class VideoScriptLinkField extends Field implements DisplayableField
{ {
public function __construct() public function __construct()
{ {
@@ -4,13 +4,12 @@ declare(strict_types=1);
namespace App\GraphQL\Schema\Queries\Models\Pagination\Wiki\Anime; namespace App\GraphQL\Schema\Queries\Models\Pagination\Wiki\Anime;
use App\Contracts\GraphQL\Fields\DeprecatedField;
use App\GraphQL\Argument\Argument; use App\GraphQL\Argument\Argument;
use App\GraphQL\Argument\SearchArgument; use App\GraphQL\Argument\SearchArgument;
use App\GraphQL\Schema\Queries\Models\Pagination\EloquentPaginationQuery; use App\GraphQL\Schema\Queries\Models\Pagination\EloquentPaginationQuery;
use App\GraphQL\Schema\Types\Wiki\Anime\AnimeThemeType; use App\GraphQL\Schema\Types\Wiki\Anime\AnimeThemeType;
class AnimeThemePaginationQuery extends EloquentPaginationQuery implements DeprecatedField class AnimeThemePaginationQuery extends EloquentPaginationQuery
{ {
public function name(): string public function name(): string
{ {
@@ -43,9 +42,4 @@ class AnimeThemePaginationQuery extends EloquentPaginationQuery implements Depre
new SearchArgument(), new SearchArgument(),
]; ];
} }
public function deprecationReason(): string
{
return 'Internal use only';
}
} }