mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-23 04:46:07 +02:00
52 lines
1.0 KiB
PHP
52 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Definition\Fields\Base;
|
|
|
|
use App\Contracts\GraphQL\Fields\DisplayableField;
|
|
use App\GraphQL\Definition\Fields\Field;
|
|
use GraphQL\Type\Definition\Type;
|
|
|
|
class CountField extends Field implements DisplayableField
|
|
{
|
|
public function __construct(
|
|
protected string $relation,
|
|
protected string $column,
|
|
protected ?string $name = null,
|
|
protected bool $nullable = false,
|
|
) {
|
|
parent::__construct($column, $name, $nullable);
|
|
}
|
|
|
|
/**
|
|
* Get the directives of the field.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function directives(): array
|
|
{
|
|
return [
|
|
'count' => [
|
|
'relation' => $this->relation,
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* The type returned by the field.
|
|
*/
|
|
public function type(): Type
|
|
{
|
|
return Type::int();
|
|
}
|
|
|
|
/**
|
|
* Determine if the field should be displayed to the user.
|
|
*/
|
|
public function canBeDisplayed(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|