fix(graphql): fix enum filter validation (#1042)

This commit is contained in:
Kyrch
2026-01-03 05:33:22 -03:00
committed by GitHub
parent d88376a289
commit 67d759a129
3 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -18,6 +18,6 @@ enum ThemeType: int implements HasLabel
#[Description('Ending')]
case ED = 1;
#[Description("Insert Song\n\nNote: Not retrieved by default, include it in the type_in argument to do so.")]
#[Description("Insert Song")]
case IN = 2;
}
+2 -3
View File
@@ -59,9 +59,8 @@ class EnumFilter extends Filter
'required',
function ($attribute, mixed $value, Closure $fail): void {
if (
! is_string($value)
|| ! enum_exists($this->enumClass)
|| Arr::first($this->enumClass::cases(), fn (UnitEnum $enum): bool => $enum->name === $value) === null
Arr::first($this->enumClass::cases(), fn (UnitEnum $enum): bool => $enum->name === $value) === null
&& ! $value instanceof BackedEnum
) {
$fail("'{$value}' does not exist in the ".class_basename($this->enumClass).' enum.');
}
+9
View File
@@ -14,6 +14,7 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Translation\PotentiallyTranslatedString;
use RuntimeException;
@@ -40,6 +41,14 @@ class ModerationRule implements ValidationRule
*/
private function validateForOpenAI(string $attribute, mixed $value, Closure $fail): void
{
$key = 'openai-moderation';
if (RateLimiter::tooManyAttempts($key, 60)) {
return;
}
RateLimiter::hit($key, 60);
try {
$response = Http::acceptJson()
->withToken(Config::get(ServiceConstants::OPENAI_BEARER_TOKEN))