feat(graphql): phohibits animes field when no unique year (#913)

This commit is contained in:
Kyrch
2025-08-06 05:32:15 -03:00
committed by GitHub
parent 6fe8385054
commit 1b5f42e601
8 changed files with 29 additions and 21 deletions
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\GraphQL\Controllers\Wiki\Anime;
use App\Enums\Models\Wiki\AnimeSeason;
use App\Exceptions\GraphQL\ClientValidationException;
use App\GraphQL\Controllers\BaseController;
use App\GraphQL\Definition\Fields\Wiki\Anime\AnimeYear\AnimeYearSeason\AnimeYearSeasonSeasonField;
use App\GraphQL\Definition\Fields\Wiki\Anime\AnimeYear\AnimeYearSeasonsField;
@@ -32,6 +33,10 @@ class AnimeYearsController extends BaseController
$season = Arr::get($args, AnimeYearsQuery::ARGUMENT_SEASON);
$year = Arr::get($args, AnimeYearsQuery::ARGUMENT_YEAR);
if (($year === null || count($year) > 1) && Arr::get($resolveInfo->getFieldSelection(1), 'seasons.animes')) {
throw new ClientValidationException("Please provide a unique 'year' argument to query the animes field.");
}
return Anime::query()
->distinct(Anime::ATTRIBUTE_YEAR)
->orderBy(Anime::ATTRIBUTE_YEAR)
@@ -38,7 +38,7 @@ abstract class BooleanField extends Field implements DisplayableField, Filterabl
public function filterDirectives(): array
{
return [
new EqFilterDirective($this, $this->type()),
new EqFilterDirective($this),
];
}
@@ -41,9 +41,9 @@ abstract class DateTimeTzField extends Field implements DisplayableField, Filter
public function filterDirectives(): array
{
return [
new EqFilterDirective($this, $this->type()),
new LesserFilterDirective($this, $this->type()),
new GreaterFilterDirective($this, $this->type()),
new EqFilterDirective($this),
new LesserFilterDirective($this),
new GreaterFilterDirective($this),
];
}
+3 -3
View File
@@ -71,9 +71,9 @@ abstract class EnumField extends Field implements DisplayableField, FilterableFi
public function filterDirectives(): array
{
return [
new EqFilterDirective($this, $this->type()),
new InFilterDirective($this, $this->type()),
new NotInFilterDirective($this, $this->type()),
new EqFilterDirective($this),
new InFilterDirective($this),
new NotInFilterDirective($this),
];
}
+5 -5
View File
@@ -42,11 +42,11 @@ abstract class FloatField extends Field implements DisplayableField, FilterableF
public function filterDirectives(): array
{
return [
new EqFilterDirective($this, $this->type()),
new InFilterDirective($this, $this->type()),
new NotInFilterDirective($this, $this->type()),
new LesserFilterDirective($this, $this->type()),
new GreaterFilterDirective($this, $this->type()),
new EqFilterDirective($this),
new InFilterDirective($this),
new NotInFilterDirective($this),
new LesserFilterDirective($this),
new GreaterFilterDirective($this),
];
}
+5 -5
View File
@@ -42,11 +42,11 @@ abstract class IntField extends Field implements DisplayableField, FilterableFie
public function filterDirectives(): array
{
return [
new EqFilterDirective($this, $this->type()),
new InFilterDirective($this, $this->type()),
new NotInFilterDirective($this, $this->type()),
new LesserFilterDirective($this, $this->type()),
new GreaterFilterDirective($this, $this->type()),
new EqFilterDirective($this),
new InFilterDirective($this),
new NotInFilterDirective($this),
new LesserFilterDirective($this),
new GreaterFilterDirective($this),
];
}
@@ -39,8 +39,8 @@ abstract class StringField extends Field implements DisplayableField, Filterable
public function filterDirectives(): array
{
return [
new EqFilterDirective($this, $this->type()),
new LikeFilterDirective($this, $this->type()),
new EqFilterDirective($this),
new LikeFilterDirective($this),
];
}
@@ -13,10 +13,13 @@ abstract readonly class FilterDirective
{
use ResolvesDirectives;
protected Type $type;
public function __construct(
protected Field $field,
protected Type $type,
) {}
) {
$this->type = $field->type();
}
/**
* The argument for the filter directive.