mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
feat(graphql): add support for IN operators in complex filtering (#1181)
This commit is contained in:
@@ -18,4 +18,6 @@ enum ComparisonOperator: string
|
||||
case GTE = '>=';
|
||||
case LIKE = '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)) {
|
||||
$field = $this->filterableFields->get($fieldName);
|
||||
|
||||
match ($field->getFilter()->getClause()) {
|
||||
Clause::WHERE => $builder->where(
|
||||
$field->getColumn(),
|
||||
ComparisonOperator::unstrictCoerce(Arr::get($where, 'operator'))->value,
|
||||
Arr::first($field->getFilter()->getFilterValues(Arr::wrap($value))),
|
||||
$logical->value
|
||||
),
|
||||
Clause::HAVING => $builder->having(
|
||||
Str::snake($field->getColumn()),
|
||||
ComparisonOperator::unstrictCoerce(Arr::get($where, 'operator'))->value,
|
||||
Arr::first($field->getFilter()->getFilterValues(Arr::wrap($value))),
|
||||
$logical->value
|
||||
),
|
||||
};
|
||||
$operator = ComparisonOperator::unstrictCoerce(Arr::get($where, 'operator'));
|
||||
$value = Arr::first($field->getFilter()->getFilterValues(Arr::wrap($value)));
|
||||
|
||||
if ($operator === ComparisonOperator::IN) {
|
||||
$builder->whereIn($field->getColumn(), Arr::wrap($value));
|
||||
} elseif ($operator === ComparisonOperator::NOTIN) {
|
||||
$builder->whereNotIn($field->getColumn(), Arr::wrap($value));
|
||||
} else {
|
||||
match ($field->getFilter()->getClause()) {
|
||||
Clause::WHERE => $builder->where(
|
||||
$field->getColumn(),
|
||||
$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 {
|
||||
|
||||
@@ -4,11 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\GraphQL\Schema\Fields\Wiki\Video\VideoScript;
|
||||
|
||||
use App\Contracts\GraphQL\Fields\DisplayableField;
|
||||
use App\GraphQL\Schema\Fields\Field;
|
||||
use App\Models\Wiki\Video\VideoScript;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
|
||||
class VideoScriptLinkField extends Field
|
||||
class VideoScriptLinkField extends Field implements DisplayableField
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
+1
-7
@@ -4,13 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\GraphQL\Schema\Queries\Models\Pagination\Wiki\Anime;
|
||||
|
||||
use App\Contracts\GraphQL\Fields\DeprecatedField;
|
||||
use App\GraphQL\Argument\Argument;
|
||||
use App\GraphQL\Argument\SearchArgument;
|
||||
use App\GraphQL\Schema\Queries\Models\Pagination\EloquentPaginationQuery;
|
||||
use App\GraphQL\Schema\Types\Wiki\Anime\AnimeThemeType;
|
||||
|
||||
class AnimeThemePaginationQuery extends EloquentPaginationQuery implements DeprecatedField
|
||||
class AnimeThemePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function name(): string
|
||||
{
|
||||
@@ -43,9 +42,4 @@ class AnimeThemePaginationQuery extends EloquentPaginationQuery implements Depre
|
||||
new SearchArgument(),
|
||||
];
|
||||
}
|
||||
|
||||
public function deprecationReason(): string
|
||||
{
|
||||
return 'Internal use only';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user