mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-28 01:34:43 +02:00
68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Schema\Queries\Models;
|
|
|
|
use App\GraphQL\Middleware\ResolveBindableArgs;
|
|
use App\GraphQL\Schema\Queries\BaseQuery;
|
|
use App\GraphQL\Schema\Types\BaseType;
|
|
use App\GraphQL\Schema\Types\EloquentType;
|
|
use Exception;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use RuntimeException;
|
|
|
|
abstract class EloquentQuery extends BaseQuery
|
|
{
|
|
public function __construct(
|
|
protected string $name,
|
|
protected bool $nullable = true,
|
|
protected bool $isList = false,
|
|
) {
|
|
$this->middleware = array_merge(
|
|
$this->middleware,
|
|
[
|
|
ResolveBindableArgs::class,
|
|
],
|
|
);
|
|
|
|
parent::__construct($name, $nullable, $isList);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
...parent::attributes(),
|
|
|
|
'model' => $this->model(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the model related to the query.
|
|
*
|
|
* @return class-string<Model>
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function model(): string
|
|
{
|
|
$baseType = $this->baseType();
|
|
|
|
if ($baseType instanceof EloquentType) {
|
|
return $baseType->model();
|
|
}
|
|
|
|
throw new RuntimeException('The base return rebing type must be an instance of EloquentType, '.($baseType instanceof BaseType ? $baseType::class : self::class).' given.');
|
|
}
|
|
|
|
protected function query(Builder $builder, array $args): Builder
|
|
{
|
|
return $builder;
|
|
}
|
|
}
|