mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-02 09:05:50 +02:00
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Definition\Fields\Pivot\Base;
|
|
|
|
use App\Contracts\GraphQL\Fields\DisplayableField;
|
|
use App\GraphQL\Definition\Fields\Field;
|
|
use App\GraphQL\Definition\Types\EloquentType;
|
|
use GraphQL\Type\Definition\ObjectType;
|
|
use GraphQL\Type\Definition\Type;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Class NodeField.
|
|
*/
|
|
class NodeField extends Field implements DisplayableField
|
|
{
|
|
/**
|
|
* Create a new field instance.
|
|
*
|
|
* @param class-string<EloquentType> $type
|
|
*/
|
|
public function __construct(
|
|
protected string $type,
|
|
) {
|
|
parent::__construct('node', nullable: false);
|
|
}
|
|
|
|
/**
|
|
* The type returned by the field.
|
|
*
|
|
* @return Type
|
|
*/
|
|
public function type(): Type
|
|
{
|
|
$type = Str::of(class_basename($this->type))
|
|
->remove('Type')
|
|
->remove('Edge')
|
|
->__toString();
|
|
|
|
// Necessary to prevent memory leak at compile time.
|
|
return new ObjectType(['name' => $type, 'fields' => []]);
|
|
}
|
|
|
|
/**
|
|
* Determine if the field should be displayed to the user.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function canBeDisplayed(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|