Files
animethemes-server/app/GraphQL/Schema/Fields/Base/Aggregate/CountField.php
T
2026-03-09 10:41:34 -03:00

40 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\GraphQL\Schema\Fields\Base\Aggregate;
use App\Contracts\GraphQL\Fields\DisplayableField;
use App\Contracts\GraphQL\Fields\FilterableField;
use App\Contracts\GraphQL\Fields\SortableField;
use App\Enums\GraphQL\Field\AggregateFunction;
use App\Enums\GraphQL\Filter\Clause;
use App\GraphQL\Filter\IntFilter;
use GraphQL\Type\Definition\Type;
class CountField extends AggregateField implements DisplayableField, FilterableField, SortableField
{
public function __construct(
protected string $aggregateRelation,
protected ?string $name = null,
protected bool $nullable = false,
) {
parent::__construct($aggregateRelation, $aggregateRelation.'Count', AggregateFunction::COUNT, '*', $nullable);
}
public function baseType(): Type
{
return Type::int();
}
public function canBeDisplayed(): bool
{
return true;
}
public function getFilter(): IntFilter
{
return new IntFilter($this->name(), $this->alias(), Clause::HAVING);
}
}