mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
refactor(graphql): rename methods (#1123)
This commit is contained in:
@@ -41,11 +41,11 @@ trait ConstrainsEagerLoads
|
||||
|
||||
/** @var array<int, Relation> $relations */
|
||||
$relations = collect($type->relations())
|
||||
->filter(fn (Relation $relation) => Arr::has($selection, $relation->getName()))
|
||||
->filter(fn (Relation $relation) => Arr::has($selection, $relation->name()))
|
||||
->all();
|
||||
|
||||
foreach ($relations as $relation) {
|
||||
$name = $relation->getName();
|
||||
$name = $relation->name();
|
||||
|
||||
$relationSelection = Arr::get($selection, "{$name}.{$name}");
|
||||
|
||||
@@ -73,12 +73,12 @@ trait ConstrainsEagerLoads
|
||||
/** @var array<int, EloquentType> $types */
|
||||
$types = collect($union->baseTypes())
|
||||
->filter(fn (BaseType $type): bool => $type instanceof EloquentType)
|
||||
->filter(fn (EloquentType $type) => Arr::has($unions, $type->getName()))
|
||||
->filter(fn (EloquentType $type) => Arr::has($unions, $type->name()))
|
||||
->all();
|
||||
|
||||
$morphConstrains = [];
|
||||
foreach ($types as $type) {
|
||||
$typeSelection = Arr::get($unions, "{$type->getName()}.selectionSet", []);
|
||||
$typeSelection = Arr::get($unions, "{$type->name()}.selectionSet", []);
|
||||
|
||||
$morphConstrains[$type->model()] = function (Builder $query) use ($typeSelection, $type): void {
|
||||
$this->processEagerLoadForType($query, $typeSelection, $type);
|
||||
@@ -96,11 +96,11 @@ trait ConstrainsEagerLoads
|
||||
$unions = Arr::get($selection, 'selectionSet.data.data.unions', []);
|
||||
|
||||
$types = collect($union->baseTypes())
|
||||
->filter(fn (BaseType $type) => Arr::has($unions, $type->getName()))
|
||||
->filter(fn (BaseType $type) => Arr::has($unions, $type->name()))
|
||||
->all();
|
||||
|
||||
foreach ($types as $type) {
|
||||
$typeSelection = Arr::get($unions, "{$type->getName()}.selectionSet", []);
|
||||
$typeSelection = Arr::get($unions, "{$type->name()}.selectionSet", []);
|
||||
|
||||
$this->processEagerLoadForType($relation->getQuery(), $typeSelection, $type);
|
||||
}
|
||||
@@ -145,11 +145,11 @@ trait ConstrainsEagerLoads
|
||||
}
|
||||
|
||||
$pivotRelations = collect($edgeType->relations())
|
||||
->filter(fn (Relation $rel) => Arr::has($edgeSelection, $rel->getName()))
|
||||
->filter(fn (Relation $rel) => Arr::has($edgeSelection, $rel->name()))
|
||||
->all();
|
||||
|
||||
foreach ($pivotRelations as $graphRelation) {
|
||||
$name = $graphRelation->getName();
|
||||
$name = $graphRelation->name();
|
||||
$relationSelection = Arr::get($edgeSelection, "{$name}.{$name}");
|
||||
$relationType = $graphRelation->baseType();
|
||||
$eloquentName = $graphRelation->getRelationName();
|
||||
|
||||
@@ -45,7 +45,7 @@ trait ResolvesArguments
|
||||
return collect($fields)
|
||||
->filter(fn (Field $field): bool => $field instanceof CreatableField)
|
||||
->map(
|
||||
fn (Field $field): Argument => new Argument($field->getName(), $field->baseType())
|
||||
fn (Field $field): Argument => new Argument($field->name(), $field->baseType())
|
||||
->required($field instanceof RequiredOnCreation)
|
||||
)
|
||||
->flatten()
|
||||
@@ -63,7 +63,7 @@ trait ResolvesArguments
|
||||
return collect($fields)
|
||||
->filter(fn (Field $field): bool => $field instanceof UpdatableField)
|
||||
->map(
|
||||
fn (Field $field): Argument => new Argument($field->getName(), $field->baseType())
|
||||
fn (Field $field): Argument => new Argument($field->name(), $field->baseType())
|
||||
->required($field instanceof RequiredOnUpdate)
|
||||
)
|
||||
->flatten()
|
||||
|
||||
@@ -13,7 +13,7 @@ class BindableArgument extends Argument
|
||||
Field&BindableField $field,
|
||||
bool $shouldRequire = true,
|
||||
) {
|
||||
parent::__construct($field->getName(), $field->baseType());
|
||||
parent::__construct($field->name(), $field->baseType());
|
||||
|
||||
$this->required($shouldRequire);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class WhereConditionsFilter extends Filter
|
||||
|
||||
public function getBaseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new WhereConditionsInput($this->type)->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new WhereConditionsInput($this->type)->name())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ class ResolveBindableArgs extends Middleware
|
||||
}
|
||||
|
||||
$bindableFields = collect($baseType->fieldClasses())
|
||||
->filter(fn (Field $field): bool => $field instanceof BindableField && Arr::has($args, $field->getName()))
|
||||
->filter(fn (Field $field): bool => $field instanceof BindableField && Arr::has($args, $field->name()))
|
||||
->all();
|
||||
|
||||
/** @var Field&BindableField $field */
|
||||
@@ -37,13 +37,13 @@ class ResolveBindableArgs extends Middleware
|
||||
|
||||
if ($resolver === null) {
|
||||
$args['model'] = $baseType->model()::query()
|
||||
->where($field->getColumn(), Arr::get($args, $field->getName()))
|
||||
->where($field->getColumn(), Arr::get($args, $field->name()))
|
||||
->firstOrFail();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$args[$field->getName()] = $resolver;
|
||||
$args[$field->name()] = $resolver;
|
||||
}
|
||||
|
||||
return $next($root, $args, $context, $resolveInfo);
|
||||
|
||||
@@ -26,14 +26,14 @@ class FilterableColumns extends EnumType
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'name' => $this->name(),
|
||||
'values' => $this->getValues()->keys()->all(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return $this->type->getName().self::SUFFIX;
|
||||
return $this->type->name().self::SUFFIX;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,6 +51,6 @@ class FilterableColumns extends EnumType
|
||||
public function getValues(): Collection
|
||||
{
|
||||
return $this->getFilterableFields()
|
||||
->mapWithKeys(fn (Field $field): array => [Str::of($field->getName())->snake()->upper()->__toString() => $field]);
|
||||
->mapWithKeys(fn (Field $field): array => [Str::of($field->name())->snake()->upper()->__toString() => $field]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ class SortableColumns extends EnumType
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
$typeName = $this->type->getName();
|
||||
$typeName = $this->type->name();
|
||||
|
||||
$name = $this->pivotType instanceof PivotType
|
||||
? $typeName.$this->pivotType->getName()
|
||||
? $typeName.$this->pivotType->name()
|
||||
: $typeName;
|
||||
|
||||
return [
|
||||
@@ -106,7 +106,7 @@ class SortableColumns extends EnumType
|
||||
->filter(fn (Relation $relation): bool => $relation instanceof BelongsToRelation && $relation->baseType() instanceof BaseType)
|
||||
->mapWithKeys(
|
||||
fn (Relation $relation): array => [
|
||||
$relation->getName() => collect($relation->baseType()->fieldClasses())
|
||||
$relation->name() => collect($relation->baseType()->fieldClasses())
|
||||
->filter(fn (Field $field): bool => $field instanceof SortableField),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -49,7 +49,7 @@ abstract class AggregateField extends Field implements FilterableField, Sortable
|
||||
public function shouldAggregate(array $args, array $selection, BaseType $type): bool
|
||||
{
|
||||
// If the field is being requested.
|
||||
if (Arr::has($selection, $this->getName())) {
|
||||
if (Arr::has($selection, $this->name())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ abstract class AggregateField extends Field implements FilterableField, Sortable
|
||||
$sortCriteria = Arr::get(new SortableColumns($type)->getAttributes(), 'criteria');
|
||||
$sorts = Arr::get($args, 'sort', []);
|
||||
foreach ($sortCriteria as $sortCriterion) {
|
||||
if (in_array($sortCriterion->__toString(), $sorts) && $sortCriterion->getSort()->getName() === $this->getName()) {
|
||||
if (in_array($sortCriterion->__toString(), $sorts) && $sortCriterion->getSort()->getName() === $this->name()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ abstract class AggregateField extends Field implements FilterableField, Sortable
|
||||
|
||||
if (filled($fieldName) && filled($fieldValue)) {
|
||||
$field = $this->filterableFields->get($fieldName);
|
||||
if ($field instanceof Field && $field->getName() === $this->getName()) {
|
||||
if ($field instanceof Field && $field->name() === $this->name()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CountAggregateField extends AggregateField implements DisplayableField, So
|
||||
|
||||
public function getFilter(): IntFilter
|
||||
{
|
||||
return new IntFilter($this->getName(), $this->alias(), Clause::HAVING);
|
||||
return new IntFilter($this->name(), $this->alias(), Clause::HAVING);
|
||||
}
|
||||
|
||||
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo): mixed
|
||||
|
||||
@@ -34,6 +34,6 @@ class CountField extends AggregateField implements DisplayableField, FilterableF
|
||||
|
||||
public function getFilter(): IntFilter
|
||||
{
|
||||
return new IntFilter($this->getName(), $this->alias(), Clause::HAVING);
|
||||
return new IntFilter($this->name(), $this->alias(), Clause::HAVING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ class ExistsField extends AggregateField implements DisplayableField
|
||||
|
||||
public function getFilter(): BooleanFilter
|
||||
{
|
||||
return new BooleanFilter($this->getName(), $this->alias(), Clause::HAVING);
|
||||
return new BooleanFilter($this->name(), $this->alias(), Clause::HAVING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ abstract class BooleanField extends Field implements DisplayableField, Filterabl
|
||||
|
||||
public function getFilter(): BooleanFilter
|
||||
{
|
||||
return new BooleanFilter($this->getName(), $this->getColumn())
|
||||
return new BooleanFilter($this->name(), $this->getColumn())
|
||||
->useEq();
|
||||
}
|
||||
|
||||
public function getSort(): Sort
|
||||
{
|
||||
return new Sort($this->getName(), $this->getColumn());
|
||||
return new Sort($this->name(), $this->getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ abstract class DateTimeTzField extends StringField
|
||||
|
||||
public function getFilter(): DateTimeTzFilter
|
||||
{
|
||||
return new DateTimeTzFilter($this->getName(), $this->getColumn())
|
||||
return new DateTimeTzFilter($this->name(), $this->getColumn())
|
||||
->useEq()
|
||||
->useLt()
|
||||
->useGt();
|
||||
|
||||
@@ -46,7 +46,7 @@ abstract class EnumField extends Field implements DisplayableField, FilterableFi
|
||||
|
||||
public function getFilter(): EnumFilter
|
||||
{
|
||||
return new EnumFilter($this->getName(), $this->enum, $this->getColumn())
|
||||
return new EnumFilter($this->name(), $this->enum, $this->getColumn())
|
||||
->useEq()
|
||||
->useIn()
|
||||
->useNotIn();
|
||||
@@ -54,6 +54,6 @@ abstract class EnumField extends Field implements DisplayableField, FilterableFi
|
||||
|
||||
public function getSort(): Sort
|
||||
{
|
||||
return new Sort($this->getName(), $this->getColumn());
|
||||
return new Sort($this->name(), $this->getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ abstract class Field
|
||||
* Get the name of the field.
|
||||
* By default, the name will be the column in camelCase.
|
||||
*/
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return $this->name ?? Str::camel($this->column);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ abstract class Field
|
||||
$baseType = $this->baseType();
|
||||
|
||||
$type = $baseType instanceof BaseType || $baseType instanceof BaseUnion
|
||||
? GraphQL::type($baseType->getName())
|
||||
? GraphQL::type($baseType->name())
|
||||
: $baseType;
|
||||
|
||||
if (! $this->nullable) {
|
||||
|
||||
@@ -25,7 +25,7 @@ abstract class FloatField extends Field implements DisplayableField, FilterableF
|
||||
|
||||
public function getFilter(): FloatFilter
|
||||
{
|
||||
return new FloatFilter($this->getName(), $this->getColumn())
|
||||
return new FloatFilter($this->name(), $this->getColumn())
|
||||
->useEq()
|
||||
->useLt()
|
||||
->useGt()
|
||||
@@ -35,6 +35,6 @@ abstract class FloatField extends Field implements DisplayableField, FilterableF
|
||||
|
||||
public function getSort(): Sort
|
||||
{
|
||||
return new Sort($this->getName(), $this->getColumn());
|
||||
return new Sort($this->name(), $this->getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ abstract class IntField extends Field implements DisplayableField, FilterableFie
|
||||
|
||||
public function getFilter(): IntFilter
|
||||
{
|
||||
return new IntFilter($this->getName(), $this->getColumn())
|
||||
return new IntFilter($this->name(), $this->getColumn())
|
||||
->useEq()
|
||||
->useLt()
|
||||
->useGt()
|
||||
@@ -35,6 +35,6 @@ abstract class IntField extends Field implements DisplayableField, FilterableFie
|
||||
|
||||
public function getSort(): Sort
|
||||
{
|
||||
return new Sort($this->getName(), $this->getColumn());
|
||||
return new Sort($this->name(), $this->getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class PlaylistTrackEntryIdField extends Field implements CreatableField, Filtera
|
||||
|
||||
public function getFilter(): IntFilter
|
||||
{
|
||||
return new IntFilter($this->getName(), $this->getColumn());
|
||||
return new IntFilter($this->name(), $this->getColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ class PlaylistTrackPlaylistField extends Field implements BindableField, Creatab
|
||||
public function bindResolver(array $args): Playlist
|
||||
{
|
||||
return Playlist::query()
|
||||
->where(Playlist::ATTRIBUTE_HASHID, Arr::get($args, $this->getName()))
|
||||
->where(Playlist::ATTRIBUTE_HASHID, Arr::get($args, $this->name()))
|
||||
->firstOrFail();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class PlaylistTrackVideoIdField extends Field implements CreatableField, Filtera
|
||||
|
||||
public function getFilter(): IntFilter
|
||||
{
|
||||
return new IntFilter($this->getName(), $this->getColumn());
|
||||
return new IntFilter($this->name(), $this->getColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,12 +14,12 @@ class LocalizedEnumField extends Field implements DisplayableField
|
||||
public function __construct(
|
||||
protected EnumField $field,
|
||||
) {
|
||||
parent::__construct($field->column, $field->getName().'Localized', $field->nullable);
|
||||
parent::__construct($field->column, $field->name().'Localized', $field->nullable);
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return "The formatted string value of the {$this->field->getName()} field";
|
||||
return "The formatted string value of the {$this->field->name()} field";
|
||||
}
|
||||
|
||||
public function baseType(): Type
|
||||
|
||||
@@ -28,7 +28,7 @@ class BelongsToManyRelation extends Relation
|
||||
$this->edgeType = new EdgeType($ownerType, $nodeType, $pivotType);
|
||||
$this->connectionType = new ConnectionType($this->edgeType);
|
||||
|
||||
GraphQL::addType($this->connectionType, $this->connectionType->getName());
|
||||
GraphQL::addType($this->connectionType, $this->connectionType->name());
|
||||
|
||||
parent::__construct(new $nodeType, $relationName);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class BelongsToManyRelation extends Relation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::type($this->connectionType->getName()));
|
||||
return Type::nonNull(GraphQL::type($this->connectionType->name()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ class HasManyRelation extends Relation
|
||||
{
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type($this->baseType()->getName()))));
|
||||
return Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type($this->baseType()->name()))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchAnimeField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new AnimeType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new AnimeType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchAnimeThemesField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new AnimeThemeType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new AnimeThemeType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchArtistsField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new ArtistType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new ArtistType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchPlaylistsField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new PlaylistType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new PlaylistType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchSeriesField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new SeriesType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new SeriesType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchSongsField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new SongType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new SongType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchStudiosField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new StudioType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new StudioType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -24,7 +24,7 @@ class SearchVideosField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new VideoType()->getName())));
|
||||
return Type::listOf(Type::nonNull(GraphQL::type(new VideoType()->name())));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -26,13 +26,13 @@ abstract class StringField extends Field implements DisplayableField, Filterable
|
||||
|
||||
public function getFilter(): Filter
|
||||
{
|
||||
return new StringFilter($this->getName(), $this->getColumn())
|
||||
return new StringFilter($this->name(), $this->getColumn())
|
||||
->useEq()
|
||||
->useLike();
|
||||
}
|
||||
|
||||
public function getSort(): Sort
|
||||
{
|
||||
return new Sort($this->getName(), $this->getColumn());
|
||||
return new Sort($this->name(), $this->getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class AnimeYearSeasonAnimeField extends Field implements DisplayableField
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::paginate($this->baseType()->getName()));
|
||||
return Type::nonNull(GraphQL::paginate($this->baseType()->name()));
|
||||
}
|
||||
|
||||
public function canBeDisplayed(): bool
|
||||
|
||||
@@ -26,7 +26,7 @@ class AnimeYearSeasonsField extends Field implements DisplayableField
|
||||
|
||||
public function baseType(): Type
|
||||
{
|
||||
$type = GraphQL::type(new AnimeYearSeasonsType()->getName());
|
||||
$type = GraphQL::type(new AnimeYearSeasonsType()->name());
|
||||
|
||||
return Type::listOf(Type::nonNull($type));
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ abstract class Input extends InputType
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->attributes['name'] = $this->getName();
|
||||
$this->attributes['name'] = $this->name();
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return class_basename($this);
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@ class WhereConditionsInput extends Input
|
||||
{
|
||||
public function __construct(protected EloquentType $type)
|
||||
{
|
||||
$this->attributes['name'] = $this->getName();
|
||||
$this->attributes['name'] = $this->name();
|
||||
|
||||
GraphQL::addType($this);
|
||||
|
||||
GraphQL::addType(new FilterableColumns($type));
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return Str::of($this->type->getName())
|
||||
return Str::of($this->type->name())
|
||||
->remove('Type')
|
||||
->append('WhereConditionsInput')
|
||||
->__toString();
|
||||
@@ -37,7 +37,7 @@ class WhereConditionsInput extends Input
|
||||
{
|
||||
return [
|
||||
'field' => [
|
||||
'type' => GraphQL::type(new FilterableColumns($this->type)->getName()),
|
||||
'type' => GraphQL::type(new FilterableColumns($this->type)->name()),
|
||||
],
|
||||
'value' => [
|
||||
'type' => GraphQL::type('Mixed'),
|
||||
@@ -47,10 +47,10 @@ class WhereConditionsInput extends Input
|
||||
'defaultValue' => ComparisonOperator::EQ->name,
|
||||
],
|
||||
'AND' => [
|
||||
'type' => Type::listOf(Type::nonNull(GraphQL::type($this->getName()))),
|
||||
'type' => Type::listOf(Type::nonNull(GraphQL::type($this->name()))),
|
||||
],
|
||||
'OR' => [
|
||||
'type' => Type::listOf(Type::nonNull(GraphQL::type($this->getName()))),
|
||||
'type' => Type::listOf(Type::nonNull(GraphQL::type($this->name()))),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ abstract class BaseMutation extends Mutation
|
||||
|
||||
protected Response $response;
|
||||
|
||||
public function __construct(
|
||||
protected string $name,
|
||||
) {
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware = array_merge(
|
||||
$this->middleware,
|
||||
[
|
||||
@@ -34,6 +33,20 @@ abstract class BaseMutation extends Mutation
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->name(),
|
||||
'description' => $this->description(),
|
||||
'baseType' => $this->baseType(),
|
||||
];
|
||||
}
|
||||
|
||||
abstract public function name(): string;
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return '';
|
||||
@@ -44,23 +57,6 @@ abstract class BaseMutation extends Mutation
|
||||
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.
|
||||
*
|
||||
@@ -70,7 +66,7 @@ abstract class BaseMutation extends Mutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return GraphQL::type($this->baseType()->getName());
|
||||
return GraphQL::type($this->baseType()->name());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,11 +24,14 @@ abstract class CreateMutation extends BaseMutation
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $model,
|
||||
protected ?string $customName = null,
|
||||
) {
|
||||
parent::__construct($customName ?? 'Create'.Str::pascal(class_basename($model)));
|
||||
public function __construct(protected string $model)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'Create'.Str::pascal(class_basename($this->model));
|
||||
}
|
||||
|
||||
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
|
||||
@@ -73,7 +76,7 @@ abstract class CreateMutation extends BaseMutation
|
||||
if ($baseType instanceof BaseType) {
|
||||
return collect($baseType->fieldClasses())
|
||||
->filter(fn (Field $field): bool => $field instanceof CreatableField)
|
||||
->mapWithKeys(fn (Field&CreatableField $field): array => [$field->getName() => $field->getCreationRules($args)])
|
||||
->mapWithKeys(fn (Field&CreatableField $field): array => [$field->name() => $field->getCreationRules($args)])
|
||||
->all();
|
||||
}
|
||||
|
||||
@@ -82,6 +85,6 @@ abstract class CreateMutation extends BaseMutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->getName()));
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->name()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,12 @@ abstract class DeleteMutation extends BaseMutation
|
||||
*/
|
||||
public function __construct(protected string $model)
|
||||
{
|
||||
parent::__construct('Delete'.Str::pascal(class_basename($model)));
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'Delete'.Str::pascal(class_basename($this->model));
|
||||
}
|
||||
|
||||
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
|
||||
@@ -59,6 +64,6 @@ abstract class DeleteMutation extends BaseMutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->getName()));
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->name()));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,9 +16,9 @@ use Illuminate\Support\Facades\App;
|
||||
|
||||
class SyncExternalProfileMutation extends BaseMutation
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('SyncExternalProfile');
|
||||
return 'SyncExternalProfile';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
@@ -48,7 +48,7 @@ class SyncExternalProfileMutation extends BaseMutation
|
||||
|
||||
return collect($type->fieldClasses())
|
||||
->filter(fn (Field $field): bool => $field instanceof BindableField)
|
||||
->mapWithKeys(fn (Field&BindableField $field): array => [$field->getName() => ['required']])
|
||||
->mapWithKeys(fn (Field&BindableField $field): array => [$field->name() => ['required']])
|
||||
->all();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class DeletePlaylistMutation extends DeleteMutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::type(new MessageResponseType()->getName()));
|
||||
return Type::nonNull(GraphQL::type(new MessageResponseType()->name()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ class DeletePlaylistTrackMutation extends DeleteMutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::type(new MessageResponseType()->getName()));
|
||||
return Type::nonNull(GraphQL::type(new MessageResponseType()->name()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,12 @@ abstract class UpdateMutation extends BaseMutation
|
||||
*/
|
||||
public function __construct(protected string $model)
|
||||
{
|
||||
parent::__construct('Update'.Str::pascal(class_basename($model)));
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'Update'.Str::pascal(class_basename($this->model));
|
||||
}
|
||||
|
||||
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
|
||||
@@ -71,7 +76,7 @@ abstract class UpdateMutation extends BaseMutation
|
||||
if ($baseType instanceof BaseType) {
|
||||
return collect($baseType->fieldClasses())
|
||||
->filter(fn (Field $field): bool => $field instanceof UpdatableField)
|
||||
->mapWithKeys(fn (Field&UpdatableField $field): array => [$field->getName() => $field->getUpdateRules($args)])
|
||||
->mapWithKeys(fn (Field&UpdatableField $field): array => [$field->name() => $field->getUpdateRules($args)])
|
||||
->all();
|
||||
}
|
||||
|
||||
@@ -80,6 +85,6 @@ abstract class UpdateMutation extends BaseMutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->getName()));
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->name()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ use Rebing\GraphQL\Support\Facades\GraphQL;
|
||||
|
||||
class ToggleLikeMutation extends BaseMutation
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('ToggleLike');
|
||||
return 'ToggleLike';
|
||||
}
|
||||
|
||||
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, $selectFields = null): bool
|
||||
@@ -51,7 +51,7 @@ class ToggleLikeMutation extends BaseMutation
|
||||
|
||||
return collect($type->fieldClasses())
|
||||
->filter(fn (Field $field): bool => $field instanceof CreatableField)
|
||||
->mapWithKeys(fn (Field&CreatableField $field): array => [$field->getName() => $field->getCreationRules($args)])
|
||||
->mapWithKeys(fn (Field&CreatableField $field): array => [$field->name() => $field->getCreationRules($args)])
|
||||
->all();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class ToggleLikeMutation extends BaseMutation
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
return GraphQL::type($this->baseType()->getName());
|
||||
return GraphQL::type($this->baseType()->name());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,12 @@ class WatchMutation extends CreateMutation
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(WatchHistory::class, 'Watch');
|
||||
parent::__construct(WatchHistory::class);
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'Watch';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -14,9 +14,9 @@ use Illuminate\Support\Facades\Date;
|
||||
|
||||
class CurrentFeaturedThemeQuery extends BaseQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('currentfeaturedtheme');
|
||||
return 'currentfeaturedtheme';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -14,9 +14,14 @@ use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class MeQuery extends BaseQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('me');
|
||||
return 'me';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Returns the data of the currently authenticated user.';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,11 +34,6 @@ class MeQuery extends BaseQuery
|
||||
return [];
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Returns the data of the currently authenticated user.';
|
||||
}
|
||||
|
||||
/**
|
||||
* The base return type of the query.
|
||||
*/
|
||||
|
||||
@@ -9,12 +9,9 @@ use App\Concerns\Actions\GraphQL\FiltersModels;
|
||||
use App\Concerns\GraphQL\ResolvesArguments;
|
||||
use App\Contracts\GraphQL\Fields\DeprecatedField;
|
||||
use App\GraphQL\Argument\Argument;
|
||||
use App\GraphQL\Argument\FirstArgument;
|
||||
use App\GraphQL\Argument\PageArgument;
|
||||
use App\GraphQL\Argument\SortArgument;
|
||||
use App\GraphQL\Criteria\Filter\FilterCriteria;
|
||||
use App\GraphQL\Filter\Filter;
|
||||
use App\GraphQL\Schema\Queries\Models\Pagination\EloquentPaginationQuery;
|
||||
use App\GraphQL\Schema\Types\BaseType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
@@ -31,7 +28,6 @@ abstract class BaseQuery extends Query
|
||||
protected Response $response;
|
||||
|
||||
public function __construct(
|
||||
protected string $name,
|
||||
protected bool $nullable = true,
|
||||
protected bool $isList = false,
|
||||
) {}
|
||||
@@ -47,17 +43,14 @@ abstract class BaseQuery extends Query
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'name' => $this->name(),
|
||||
'description' => $this->description(),
|
||||
'baseType' => $this->baseType(),
|
||||
'deprecationReason' => $this instanceof DeprecatedField ? $this->deprecationReason() : null,
|
||||
];
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
abstract public function name(): string;
|
||||
|
||||
abstract public function description(): string;
|
||||
|
||||
@@ -72,16 +65,11 @@ abstract class BaseQuery extends Query
|
||||
|
||||
$baseType = $this->baseType();
|
||||
|
||||
if ($this instanceof EloquentPaginationQuery) {
|
||||
$arguments[] = new FirstArgument();
|
||||
$arguments[] = new PageArgument();
|
||||
}
|
||||
|
||||
if ($baseType instanceof BaseType && $baseType->hasFilterableColumns()) {
|
||||
if ($baseType->hasFilterableColumns()) {
|
||||
$arguments[] = FilterCriteria::getFilters($baseType)->map(fn (Filter $filter): array => $filter->getArguments())->flatten();
|
||||
}
|
||||
|
||||
if ($baseType instanceof BaseType && $this instanceof EloquentPaginationQuery && $baseType->hasSortableColumns()) {
|
||||
if ($baseType->hasSortableColumns()) {
|
||||
$arguments[] = new SortArgument($baseType);
|
||||
}
|
||||
|
||||
@@ -93,16 +81,13 @@ abstract class BaseQuery extends Query
|
||||
*/
|
||||
public function toType(): Type
|
||||
{
|
||||
return GraphQL::type($this->baseType()->getName());
|
||||
return GraphQL::type($this->baseType()->name());
|
||||
}
|
||||
|
||||
/**
|
||||
* The base return rebing type of the query.
|
||||
*/
|
||||
public function baseType(): ?BaseType
|
||||
{
|
||||
return null;
|
||||
}
|
||||
abstract public function baseType(): BaseType;
|
||||
|
||||
public function type(): Type
|
||||
{
|
||||
|
||||
@@ -6,9 +6,7 @@ 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;
|
||||
@@ -16,7 +14,6 @@ use RuntimeException;
|
||||
abstract class EloquentQuery extends BaseQuery
|
||||
{
|
||||
public function __construct(
|
||||
protected string $name,
|
||||
protected bool $nullable = true,
|
||||
protected bool $isList = false,
|
||||
) {
|
||||
@@ -27,7 +24,7 @@ abstract class EloquentQuery extends BaseQuery
|
||||
],
|
||||
);
|
||||
|
||||
parent::__construct($name, $nullable, $isList);
|
||||
parent::__construct($nullable, $isList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +44,7 @@ abstract class EloquentQuery extends BaseQuery
|
||||
*
|
||||
* @return class-string<Model>
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function model(): string
|
||||
{
|
||||
@@ -57,7 +54,7 @@ abstract class EloquentQuery extends BaseQuery
|
||||
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.');
|
||||
throw new RuntimeException(sprintf('The base return rebing type must be an instance of EloquentType, %s given.', $baseType::class));
|
||||
}
|
||||
|
||||
protected function query(Builder $builder, array $args): Builder
|
||||
|
||||
@@ -10,9 +10,9 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class AnnouncementPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('announcementPagination');
|
||||
return 'announcementPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -10,9 +10,9 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DumpPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('dumpPagination');
|
||||
return 'dumpPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -12,9 +12,9 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class FeaturePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('featurePagination');
|
||||
return 'featurePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -13,9 +13,9 @@ use Illuminate\Support\Facades\Date;
|
||||
|
||||
class FeaturedThemePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('featuredthemePagination');
|
||||
return 'featuredthemePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Document\PageType;
|
||||
|
||||
class PagePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('pagePagination');
|
||||
return 'pagePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -5,8 +5,10 @@ declare(strict_types=1);
|
||||
namespace App\GraphQL\Schema\Queries\Models\Pagination;
|
||||
|
||||
use App\Actions\GraphQL\IndexAction;
|
||||
use App\GraphQL\Argument\Argument;
|
||||
use App\GraphQL\Argument\FirstArgument;
|
||||
use App\GraphQL\Argument\PageArgument;
|
||||
use App\GraphQL\Schema\Queries\Models\EloquentQuery;
|
||||
use App\GraphQL\Schema\Types\BaseType;
|
||||
use Closure;
|
||||
use GraphQL\Type\Definition\ResolveInfo;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
@@ -15,13 +17,12 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Rebing\GraphQL\Support\Facades\GraphQL;
|
||||
use RuntimeException;
|
||||
|
||||
abstract class EloquentPaginationQuery extends EloquentQuery
|
||||
{
|
||||
public function __construct(protected string $name)
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($name, false, true);
|
||||
parent::__construct(false, true);
|
||||
}
|
||||
|
||||
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
|
||||
@@ -34,6 +35,21 @@ abstract class EloquentPaginationQuery extends EloquentQuery
|
||||
return ($this->response = Gate::inspect('viewAny', [$this->model(), ...$args]))->allowed();
|
||||
}
|
||||
|
||||
/**
|
||||
* The arguments of the class resolve as customs class helper.
|
||||
*
|
||||
* @return Argument[]
|
||||
*/
|
||||
public function arguments(): array
|
||||
{
|
||||
return [
|
||||
...parent::arguments(),
|
||||
|
||||
new FirstArgument(),
|
||||
new PageArgument(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the pagination query.
|
||||
*
|
||||
@@ -55,10 +71,8 @@ abstract class EloquentPaginationQuery extends EloquentQuery
|
||||
*/
|
||||
public function type(): Type
|
||||
{
|
||||
$baseType = $this->baseType();
|
||||
$this->baseType();
|
||||
|
||||
throw_unless($baseType instanceof BaseType, RuntimeException::class, "baseType not defined for query {$this->getName()}");
|
||||
|
||||
return Type::nonNull(GraphQL::paginate($this->baseType()->getName()));
|
||||
return Type::nonNull(GraphQL::paginate($this->baseType()->name()));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,9 +18,9 @@ class ExternalProfilePaginationQuery extends EloquentPaginationQuery
|
||||
EnabledOnlyOnLocalhost::class,
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('externalprofilePagination');
|
||||
return 'externalprofilePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -15,9 +15,9 @@ use Illuminate\Support\Arr;
|
||||
|
||||
class PlaylistTrackPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('playlisttrackPagination');
|
||||
return 'playlisttrackPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -15,9 +15,9 @@ use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PlaylistPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('playlistPagination');
|
||||
return 'playlistPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -10,9 +10,9 @@ use App\GraphQL\Schema\Types\Wiki\Anime\AnimeSynonymType;
|
||||
|
||||
class AnimeSynonymPaginationQuery extends EloquentPaginationQuery implements DeprecatedField
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('animesynonymPagination');
|
||||
return 'animesynonymPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -11,9 +11,9 @@ use App\GraphQL\Schema\Types\Wiki\Anime\AnimeThemeType;
|
||||
|
||||
class AnimeThemePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('animethemePagination');
|
||||
return 'animethemePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\Anime\Theme\AnimeThemeEntryType;
|
||||
|
||||
class AnimeThemeEntryPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('animethemeentryPagination');
|
||||
return 'animethemeentryPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -11,9 +11,9 @@ use App\GraphQL\Schema\Types\Wiki\AnimeType;
|
||||
|
||||
class AnimePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('animePagination');
|
||||
return 'animePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -11,9 +11,9 @@ use App\GraphQL\Schema\Types\Wiki\ArtistType;
|
||||
|
||||
class ArtistPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('artistPagination');
|
||||
return 'artistPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\AudioType;
|
||||
|
||||
class AudioPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('audioPagination');
|
||||
return 'audioPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\ExternalResourceType;
|
||||
|
||||
class ExternalResourcePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('externalresourcePagination');
|
||||
return 'externalresourcePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\ImageType;
|
||||
|
||||
class ImagePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('imagePagination');
|
||||
return 'imagePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -11,9 +11,9 @@ use App\GraphQL\Schema\Types\Wiki\SeriesType;
|
||||
|
||||
class SeriesPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('seriesPagination');
|
||||
return 'seriesPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\Song\MembershipType;
|
||||
|
||||
class MembershipPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('membershipPagination');
|
||||
return 'membershipPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\Song\PerformanceType;
|
||||
|
||||
class PerformancePaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('performancePagination');
|
||||
return 'performancePagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\SongType;
|
||||
|
||||
class SongPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('songPagination');
|
||||
return 'songPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -11,9 +11,9 @@ use App\GraphQL\Schema\Types\Wiki\StudioType;
|
||||
|
||||
class StudioPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('studioPagination');
|
||||
return 'studioPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\SynonymType;
|
||||
|
||||
class SynonymPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('synonymPagination');
|
||||
return 'synonymPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\ThemeGroupType;
|
||||
|
||||
class ThemeGroupPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('themegroupPagination');
|
||||
return 'themegroupPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\Video\VideoScriptType;
|
||||
|
||||
class VideoScriptPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('videoscriptPagination');
|
||||
return 'videoscriptPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\VideoType;
|
||||
|
||||
class VideoPaginationQuery extends EloquentPaginationQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('videoPagination');
|
||||
return 'videoPagination';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Document\PageType;
|
||||
|
||||
class PageQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('page');
|
||||
return 'page';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace App\GraphQL\Schema\Queries\Models\Singular;
|
||||
use App\Actions\GraphQL\ShowAction;
|
||||
use App\GraphQL\Argument\Argument;
|
||||
use App\GraphQL\Schema\Queries\Models\EloquentQuery;
|
||||
use App\GraphQL\Schema\Types\BaseType;
|
||||
use Closure;
|
||||
use GraphQL\Type\Definition\ResolveInfo;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
@@ -15,7 +14,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Rebing\GraphQL\Support\Facades\GraphQL;
|
||||
use RuntimeException;
|
||||
|
||||
abstract class EloquentSingularQuery extends EloquentQuery
|
||||
{
|
||||
@@ -40,11 +38,8 @@ abstract class EloquentSingularQuery extends EloquentQuery
|
||||
public function arguments(): array
|
||||
{
|
||||
$arguments = [];
|
||||
$baseType = $this->baseType();
|
||||
|
||||
if ($baseType instanceof BaseType) {
|
||||
$arguments[] = $this->resolveBindArguments($baseType->fieldClasses());
|
||||
}
|
||||
$arguments[] = $this->resolveBindArguments($this->baseType()->fieldClasses());
|
||||
|
||||
return Arr::flatten($arguments);
|
||||
}
|
||||
@@ -54,11 +49,7 @@ abstract class EloquentSingularQuery extends EloquentQuery
|
||||
*/
|
||||
public function type(): Type
|
||||
{
|
||||
$baseType = $this->baseType();
|
||||
|
||||
throw_unless($baseType instanceof BaseType, RuntimeException::class, "baseType not defined for query {$this->getName()}");
|
||||
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->getName()));
|
||||
return Type::nonNull(GraphQL::type($this->baseType()->name()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,9 +12,9 @@ use Illuminate\Support\Arr;
|
||||
|
||||
class PlaylistTrackQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('playlisttrack');
|
||||
return 'playlisttrack';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\List\PlaylistType;
|
||||
|
||||
class PlaylistQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('playlist');
|
||||
return 'playlist';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\AnimeType;
|
||||
|
||||
class AnimeQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('anime');
|
||||
return 'anime';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\ArtistType;
|
||||
|
||||
class ArtistQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('artist');
|
||||
return 'artist';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\SeriesType;
|
||||
|
||||
class SeriesQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('series');
|
||||
return 'series';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\StudioType;
|
||||
|
||||
class StudioQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('studio');
|
||||
return 'studio';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -9,9 +9,9 @@ use App\GraphQL\Schema\Types\Wiki\VideoType;
|
||||
|
||||
class VideoQuery extends EloquentSingularQuery
|
||||
{
|
||||
public function __construct()
|
||||
public function name(): string
|
||||
{
|
||||
parent::__construct('video');
|
||||
return 'video';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -42,7 +42,12 @@ class SearchQuery extends BaseQuery
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('search', false);
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'search';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -33,7 +33,12 @@ class AnimeThemeShuffleQuery extends BaseQuery
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('animethemeShuffle', false, true);
|
||||
parent::__construct(false, true);
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'animethemeShuffle';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -24,7 +24,12 @@ class AnimeYearsQuery extends BaseQuery
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('animeyears', false, true);
|
||||
parent::__construct(false, true);
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'animeyears';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -29,7 +29,12 @@ class FindAnimeByExternalSiteQuery extends BaseQuery
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('findAnimeByExternalSite', false, true);
|
||||
parent::__construct(false, true);
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'findAnimeByExternalSite';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
|
||||
@@ -21,7 +21,7 @@ abstract class BaseType extends RebingType
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'name' => $this->name(),
|
||||
'description' => $this->description(),
|
||||
'baseType' => $this,
|
||||
];
|
||||
@@ -31,7 +31,7 @@ abstract class BaseType extends RebingType
|
||||
* The name displayed of type.
|
||||
* By default, it will base on the class name without 'Type'.
|
||||
*/
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return Str::of(class_basename($this))
|
||||
->remove('Type')
|
||||
@@ -74,7 +74,7 @@ abstract class BaseType extends RebingType
|
||||
{
|
||||
$relations = collect($this->relations())
|
||||
->mapWithKeys(fn (Relation $relation): array => [
|
||||
$relation->getName() => [
|
||||
$relation->name() => [
|
||||
'type' => $relation->type(),
|
||||
'args' => $relation->args(),
|
||||
'resolve' => $relation->resolve(...),
|
||||
@@ -86,7 +86,7 @@ abstract class BaseType extends RebingType
|
||||
->reject(fn (Field $field): bool => $field instanceof Relation)
|
||||
->filter(fn (Field $field): bool => $field instanceof DisplayableField && $field->canBeDisplayed())
|
||||
->mapWithKeys(fn (Field $field): array => [
|
||||
$field->getName() => [
|
||||
$field->name() => [
|
||||
'type' => $field->type(),
|
||||
'description' => $field->description(),
|
||||
'alias' => $field->getColumn(),
|
||||
|
||||
@@ -21,7 +21,7 @@ class ConnectionType extends RebingType
|
||||
|
||||
public function __construct(protected EdgeType $edgeType)
|
||||
{
|
||||
GraphQL::addType($edgeType, $edgeType->getName());
|
||||
GraphQL::addType($edgeType, $edgeType->name());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ class ConnectionType extends RebingType
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'name' => $this->name(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ class ConnectionType extends RebingType
|
||||
{
|
||||
return [
|
||||
'pageInfo' => [
|
||||
'type' => Type::nonNull(GraphQL::type(new PaginationInfoType()->getName())),
|
||||
'type' => Type::nonNull(GraphQL::type(new PaginationInfoType()->name())),
|
||||
'description' => 'Pagination information about the list of edges.',
|
||||
'resolve' => fn (LengthAwarePaginator $paginator): LengthAwarePaginator => $paginator,
|
||||
],
|
||||
'edges' => [
|
||||
'type' => Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type($this->edgeType->getName())))),
|
||||
'type' => Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type($this->edgeType->name())))),
|
||||
'description' => "A list of {$this->getNodeTypeName()} edges.",
|
||||
'resolve' => $this->edgesResolver(...),
|
||||
],
|
||||
@@ -64,9 +64,9 @@ class ConnectionType extends RebingType
|
||||
* Get the name of the connection.
|
||||
* Template: {edgeType - Edge}Connection.
|
||||
*/
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return Str::of($this->edgeType->getName())
|
||||
return Str::of($this->edgeType->name())
|
||||
->remove('Edge')
|
||||
->append('Connection')
|
||||
->__toString();
|
||||
|
||||
@@ -25,7 +25,7 @@ class EdgeType extends BaseType
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'name' => $this->name(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class EdgeType extends BaseType
|
||||
{
|
||||
$relations = collect($this->relations())
|
||||
->flatMap(fn (Relation $relation): array => [
|
||||
$relation->getName() => [
|
||||
$relation->name() => [
|
||||
'type' => $relation->type(),
|
||||
'alias' => $relation->getRelationName(),
|
||||
'resolve' => $relation->resolve(...),
|
||||
@@ -51,7 +51,7 @@ class EdgeType extends BaseType
|
||||
->reject(fn (Field $field): bool => $field instanceof Relation)
|
||||
->prepend(new NodeField($this->nodeType))
|
||||
->flatMap(fn (Field $field): array => [
|
||||
$field->getName() => [
|
||||
$field->name() => [
|
||||
'type' => $field->type(),
|
||||
'description' => $field->description(),
|
||||
'alias' => $field->getColumn(),
|
||||
@@ -68,10 +68,10 @@ class EdgeType extends BaseType
|
||||
* Template: {parentType}{nodeType}Edge.
|
||||
* Template: {nodeType}Edge.
|
||||
*/
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return Str::of('')
|
||||
->when($this->pivotType instanceof PivotType, fn (Stringable $string) => $string->append($this->parentType->getName()))
|
||||
->when($this->pivotType instanceof PivotType, fn (Stringable $string) => $string->append($this->parentType->name()))
|
||||
->append(class_basename($this->nodeType))
|
||||
->remove('Type')
|
||||
->append('Edge')
|
||||
|
||||
@@ -18,7 +18,7 @@ abstract class BaseUnion extends UnionType
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'name' => $this->name(),
|
||||
'description' => $this->description(),
|
||||
];
|
||||
}
|
||||
@@ -27,7 +27,7 @@ abstract class BaseUnion extends UnionType
|
||||
* The name of the union type.
|
||||
* By default, it will be the class name.
|
||||
*/
|
||||
public function getName(): string
|
||||
public function name(): string
|
||||
{
|
||||
return class_basename($this);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ abstract class BaseUnion extends UnionType
|
||||
public function types(): array
|
||||
{
|
||||
return collect($this->baseTypes())
|
||||
->map(fn (BaseType $type) => GraphQL::type($type->getName()))
|
||||
->map(fn (BaseType $type) => GraphQL::type($type->name()))
|
||||
->all();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ abstract class BaseUnion extends UnionType
|
||||
->filter(fn (BaseType $type): bool => $type instanceof EloquentType)
|
||||
->first(fn (EloquentType $type): bool => $type->model() === $value::class);
|
||||
|
||||
return GraphQL::type($baseType->getName());
|
||||
return GraphQL::type($baseType->name());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,6 +37,6 @@ class NotificationUnion extends BaseUnion
|
||||
default => throw new RuntimeException("Type not specified for notification {$value->type}"),
|
||||
};
|
||||
|
||||
return GraphQL::type($type->getName());
|
||||
return GraphQL::type($type->name());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user