mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-27 09:14:43 +02:00
43 lines
983 B
PHP
43 lines
983 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Schema\Fields;
|
|
|
|
use App\Contracts\GraphQL\Fields\DisplayableField;
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
use GraphQL\Type\Definition\Type;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class LocalizedEnumField extends Field implements DisplayableField
|
|
{
|
|
public function __construct(
|
|
protected EnumField $field,
|
|
) {
|
|
parent::__construct($field->column, $field->getName().'Localized', $field->nullable);
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return "The formatted string value of the {$this->field->getName()} field";
|
|
}
|
|
|
|
public function baseType(): Type
|
|
{
|
|
return Type::string();
|
|
}
|
|
|
|
/**
|
|
* Resolve the field.
|
|
*/
|
|
public function resolve(mixed $root, array $args, $context, ResolveInfo $resolveInfo): mixed
|
|
{
|
|
return Arr::get($root, $this->column)?->localize();
|
|
}
|
|
|
|
public function canBeDisplayed(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|