Skip to content

Commit

Permalink
fix(graphql/@sortby): Random order will be available only for Query…
Browse files Browse the repository at this point in the history
… and Eloquent builders.
  • Loading branch information
LastDragon-ru committed Jan 5, 2024
1 parent 58719df commit 7ffc919
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,6 @@ input SortByScoutClauseNested {
nested: SortByScoutClauseNested
@sortByOperatorProperty

"""
By random
"""
random: SortByTypeFlag
@sortByOperatorRandom

"""
Property clause.
"""
Expand Down Expand Up @@ -478,12 +472,6 @@ input SortByScoutClauseProperties {
"""
nestedNotNull: SortByScoutClauseNested
@sortByOperatorProperty

"""
By random
"""
random: SortByTypeFlag
@sortByOperatorRandom
}

interface Eloquent
Expand Down
7 changes: 7 additions & 0 deletions packages/graphql/src/SortBy/Operators/Extra/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Override;

use function array_merge;
use function is_a;

class Random extends BaseOperator {
// <editor-fold desc="Directive">
Expand Down Expand Up @@ -48,6 +49,12 @@ public function getFieldType(TypeProvider $provider, TypeSource $source): string
return $provider->getType(Flag::class, $source);
}

#[Override]
public function isBuilderSupported(string $builder): bool {
return is_a($builder, EloquentBuilder::class, true)
|| is_a($builder, QueryBuilder::class, true);
}

#[Override]
public function call(Handler $handler, object $builder, Property $property, Argument $argument): object {
if (!($builder instanceof EloquentBuilder || $builder instanceof QueryBuilder)) {
Expand Down

0 comments on commit 7ffc919

Please sign in to comment.