diff --git a/packages/graphql/src/Builder/Traits/BuilderHelperFactory.php b/packages/graphql/src/Builder/Traits/BuilderHelperFactory.php index 1d87239df..f37dca416 100644 --- a/packages/graphql/src/Builder/Traits/BuilderHelperFactory.php +++ b/packages/graphql/src/Builder/Traits/BuilderHelperFactory.php @@ -37,15 +37,22 @@ private function addHelper(string $builder, string $helper): static { return $this; } - private function getHelper(object $builder): ?object { - if (!array_key_exists($builder::class, $this->instances)) { - $class = $this->getHelperClass($builder::class); - $this->instances[$builder::class] = $class + /** + * @param object|class-string $builder + */ + private function getHelper(object|string $builder): ?object { + if (is_object($builder)) { + $builder = $builder::class; + } + + if (!array_key_exists($builder, $this->instances)) { + $class = $this->getHelperClass($builder); + $this->instances[$builder] = $class ? Container::getInstance()->make($class) : null; } - return $this->instances[$builder::class]; + return $this->instances[$builder]; } /** diff --git a/packages/graphql/src/SortBy/Contracts/SorterFactory.php b/packages/graphql/src/SortBy/Contracts/SorterFactory.php index 9bbd79269..590b15884 100644 --- a/packages/graphql/src/SortBy/Contracts/SorterFactory.php +++ b/packages/graphql/src/SortBy/Contracts/SorterFactory.php @@ -14,9 +14,9 @@ interface SorterFactory { public function isSupported(object|string $builder): bool; /** - * @param TBuilder $builder + * @param TBuilder|class-string $builder * * @return ?Sorter */ - public function create(object $builder): ?Sorter; + public function create(object|string $builder): ?Sorter; } diff --git a/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql b/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql index d4f491809..4c6090c3f 100644 --- a/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql +++ b/packages/graphql/src/SortBy/Directives/DirectiveTest/Scout.expected.graphql @@ -516,18 +516,6 @@ input SortByScoutClauseNested { nested: SortByScoutClauseNested @sortByOperatorFieldObject - """ - NULLs first - """ - nullsFirst: SortByScoutClauseNested - @sortByOperatorNullsFirst - - """ - NULLs last - """ - nullsLast: SortByScoutClauseNested - @sortByOperatorNullsLast - """ Field clause. """ @@ -608,18 +596,6 @@ input SortByScoutClauseProperties { nestedNotNull: SortByScoutClauseNested @sortByOperatorFieldObject - """ - NULLs first - """ - nullsFirst: SortByScoutClauseProperties - @sortByOperatorNullsFirst - - """ - NULLs last - """ - nullsLast: SortByScoutClauseProperties - @sortByOperatorNullsLast - """ Field clause. """ diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php index ead7d7f31..5e6940408 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php @@ -47,7 +47,7 @@ public function getFieldDescription(): string { #[Override] public function isAvailable(string $builder, Context $context): bool { - return $this->factory->isSupported($builder); + return (bool) $this->factory->create($builder)?->isNullsSupported(); } #[Override] diff --git a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php index 1838a42a4..5e9f0d223 100644 --- a/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php +++ b/packages/graphql/src/SortBy/Operators/Extra/NullsLast.php @@ -47,7 +47,7 @@ public function getFieldDescription(): string { #[Override] public function isAvailable(string $builder, Context $context): bool { - return $this->factory->isSupported($builder); + return (bool) $this->factory->create($builder)?->isNullsSupported(); } #[Override] diff --git a/packages/graphql/src/SortBy/SorterFactory.php b/packages/graphql/src/SortBy/SorterFactory.php index fc53e9ffa..02f4d13de 100644 --- a/packages/graphql/src/SortBy/SorterFactory.php +++ b/packages/graphql/src/SortBy/SorterFactory.php @@ -35,7 +35,7 @@ public function isSupported(string|object $builder): bool { } #[Override] - public function create(object $builder): ?SorterContract { + public function create(object|string $builder): ?SorterContract { $helper = $this->getHelper($builder); assert($helper instanceof SorterContract); diff --git a/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql b/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql index 3bee4437d..9792ac562 100644 --- a/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql +++ b/packages/graphql/src/Stream/Directives/DirectiveTest~scout-expected.graphql @@ -36,18 +36,6 @@ on | INPUT_FIELD_DEFINITION | SCALAR -directive @sortByOperatorNullsFirst -on - | ENUM - | INPUT_FIELD_DEFINITION - | SCALAR - -directive @sortByOperatorNullsLast -on - | ENUM - | INPUT_FIELD_DEFINITION - | SCALAR - """ Splits list of items into the chunks and returns one chunk specified by an offset or a cursor. @@ -151,18 +139,6 @@ input SortByScoutClauseTestObject { """ id: SortByTypeDirection @sortByOperatorField - - """ - NULLs first - """ - nullsFirst: SortByScoutClauseTestObject - @sortByOperatorNullsFirst - - """ - NULLs last - """ - nullsLast: SortByScoutClauseTestObject - @sortByOperatorNullsLast } """