Files
animethemes-server/app/GraphQL/Schema/Mutations/BaseMutation.php
T
2026-02-15 16:35:04 -03:00

89 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\GraphQL\Schema\Mutations;
use App\Concerns\GraphQL\ResolvesArguments;
use App\GraphQL\Argument\Argument;
use App\GraphQL\Middleware\AuthMutation;
use App\GraphQL\Middleware\ResolveBindableArgs;
use App\GraphQL\Schema\Types\BaseType;
use App\GraphQL\Schema\Unions\BaseUnion;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Illuminate\Auth\Access\Response;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Support\Mutation;
abstract class BaseMutation extends Mutation
{
use ResolvesArguments;
protected Response $response;
public function __construct(
protected string $name,
) {
$this->middleware = array_merge(
$this->middleware,
[
AuthMutation::class,
ResolveBindableArgs::class,
],
);
}
public function description(): string
{
return '';
}
public function getAuthorizationMessage(): string
{
return $this->response->message() ?? 'Unauthorized';
}
/**
* @return array<string, mixed>
*/
public function attributes(): array
{
return [
'name' => $this->getName(),
'description' => $this->description(),
'baseType' => $this->baseType(),
];
}
public function getName(): string
{
return $this->name;
}
/**
* The arguments of the mutation.
*
* @return Argument[]
*/
abstract public function arguments(): array;
public function type(): Type
{
return GraphQL::type($this->baseType()->getName());
}
/**
* The base return type of the mutation.
*/
public function baseType(): BaseType|BaseUnion|null
{
return null;
}
/**
* @param array<string, mixed> $args
*/
abstract public function resolve($root, array $args, $context, ResolveInfo $resolveInfo): mixed;
}