mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-25 08:14:29 +02:00
65 lines
1.2 KiB
PHP
65 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Argument;
|
|
|
|
use GraphQL\Type\Definition\Type;
|
|
|
|
class Argument
|
|
{
|
|
protected bool $required = false;
|
|
protected mixed $defaultValue = null;
|
|
|
|
public function __construct(
|
|
protected string $name,
|
|
public Type|string $returnType,
|
|
) {}
|
|
|
|
/**
|
|
* Mark the argument as required.
|
|
*/
|
|
public function required(bool $condition = true): static
|
|
{
|
|
$this->required = $condition;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Append a default value to the argument.
|
|
*/
|
|
public function withDefaultValue(mixed $value): static
|
|
{
|
|
$this->defaultValue = $value;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get the name of the argument.
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
/**
|
|
* Get the default value.
|
|
*/
|
|
public function getDefaultValue(): mixed
|
|
{
|
|
return $this->defaultValue;
|
|
}
|
|
|
|
/**
|
|
* Get the type of the argument.
|
|
*/
|
|
public function getType(): Type
|
|
{
|
|
return $this->required
|
|
? Type::nonNull($this->returnType)
|
|
: $this->returnType;
|
|
}
|
|
}
|