From 7ffc919981deb9c343a43c3ce86f27a883739727 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:42:36 +0400 Subject: [PATCH] fix(graphql/@sortBy): `Random` order will be available only for Query and Eloquent builders. --- .../Directives/DirectiveTest~full-expected.graphql | 12 ------------ .../graphql/src/SortBy/Operators/Extra/Random.php | 7 +++++++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest~full-expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest~full-expected.graphql index 8827cf191..cfea3a223 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest~full-expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest~full-expected.graphql @@ -399,12 +399,6 @@ input SortByScoutClauseNested { nested: SortByScoutClauseNested @sortByOperatorProperty - """ - By random - """ - random: SortByTypeFlag - @sortByOperatorRandom - """ Property clause. """ @@ -478,12 +472,6 @@ input SortByScoutClauseProperties { """ nestedNotNull: SortByScoutClauseNested @sortByOperatorProperty - - """ - By random - """ - random: SortByTypeFlag - @sortByOperatorRandom } interface Eloquent diff --git a/packages/graphql/src/SortBy/Operators/Extra/Random.php b/packages/graphql/src/SortBy/Operators/Extra/Random.php index e040897b9..a725c4c4d 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/Random.php +++ b/packages/graphql/src/SortBy/Operators/Extra/Random.php @@ -16,6 +16,7 @@ use Override; use function array_merge; +use function is_a; class Random extends BaseOperator { // @@ -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)) {