From 224a69a10fa9c8533f31554baa0ada2a7581e5e3 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:31:29 +0400 Subject: [PATCH] deprecate(graphql): `*:getDirectiveLocations()`/`*:getLocations()`, please use `*::locations()` instead. --- .../Directives/ExtendOperatorsDirective.php | 18 +++++++++++++++--- .../Builder/Directives/IgnoredDirective.php | 18 +++++++++++++++--- .../Builder/Directives/OperatorDirective.php | 17 ++++++++++++++--- .../Builder/Directives/OperatorsDirective.php | 2 +- .../graphql/src/SearchBy/Operators/Child.php | 2 +- .../Operators/Complex/Relationship.php | 2 +- .../src/SearchBy/Operators/Condition.php | 2 +- .../graphql/src/SearchBy/Operators/Field.php | 2 +- .../src/SearchBy/Operators/Logical/Logical.php | 2 +- .../src/SortBy/Directives/DirectiveTest.php | 4 ++-- .../graphql/src/SortBy/Operators/Child.php | 2 +- .../src/SortBy/Operators/Extra/NullsFirst.php | 2 +- .../src/SortBy/Operators/Extra/NullsLast.php | 2 +- .../src/SortBy/Operators/Extra/Random.php | 2 +- .../graphql/src/SortBy/Operators/Field.php | 2 +- packages/graphql/src/SortBy/Operators/Sort.php | 2 +- 16 files changed, 58 insertions(+), 23 deletions(-) diff --git a/packages/graphql/src/Builder/Directives/ExtendOperatorsDirective.php b/packages/graphql/src/Builder/Directives/ExtendOperatorsDirective.php index ef723ac6e..cc19c32cf 100644 --- a/packages/graphql/src/Builder/Directives/ExtendOperatorsDirective.php +++ b/packages/graphql/src/Builder/Directives/ExtendOperatorsDirective.php @@ -8,6 +8,7 @@ use Nuwave\Lighthouse\Schema\Directives\BaseDirective; use Override; +use function array_merge; use function array_unique; use function implode; @@ -19,7 +20,7 @@ public function __construct() { #[Override] public static function definition(): string { $name = DirectiveLocator::directiveName(static::class); - $locations = implode(' | ', array_unique(static::getDirectiveLocations())); + $locations = implode(' | ', array_unique(static::locations())); return << */ - protected static function getDirectiveLocations(): array { - return [ + protected static function locations(): array { + return array_merge(static::getDirectiveLocations(), [ DirectiveLocation::SCALAR, DirectiveLocation::ENUM, + ]); + } + + /** + * @deprecated 6.0.0 Use {@see self::locations()} instead. + * + * @return list + */ + protected static function getDirectiveLocations(): array { + return [ + // empty ]; } diff --git a/packages/graphql/src/Builder/Directives/IgnoredDirective.php b/packages/graphql/src/Builder/Directives/IgnoredDirective.php index 866e4cc9f..758ae83e9 100644 --- a/packages/graphql/src/Builder/Directives/IgnoredDirective.php +++ b/packages/graphql/src/Builder/Directives/IgnoredDirective.php @@ -7,6 +7,7 @@ use Nuwave\Lighthouse\Schema\Directives\BaseDirective; use Override; +use function array_merge; use function array_unique; use function implode; @@ -18,7 +19,7 @@ public function __construct() { #[Override] public static function definition(): string { $name = DirectiveLocator::directiveName(static::class); - $locations = implode(' | ', array_unique(static::getDirectiveLocations())); + $locations = implode(' | ', array_unique(static::locations())); return << */ - protected static function getDirectiveLocations(): array { - return [ + protected static function locations(): array { + return array_merge(static::getDirectiveLocations(), [ DirectiveLocation::FIELD_DEFINITION, DirectiveLocation::INPUT_FIELD_DEFINITION, DirectiveLocation::OBJECT, DirectiveLocation::INPUT_OBJECT, DirectiveLocation::ENUM, DirectiveLocation::SCALAR, + ]); + } + + /** + * @deprecated 6.0.0 Use {@see self::locations()} instead. + * + * @return list + */ + protected static function getDirectiveLocations(): array { + return [ + // empty ]; } } diff --git a/packages/graphql/src/Builder/Directives/OperatorDirective.php b/packages/graphql/src/Builder/Directives/OperatorDirective.php index 0189a3f9f..3c6e4c663 100644 --- a/packages/graphql/src/Builder/Directives/OperatorDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorDirective.php @@ -31,7 +31,7 @@ public static function definition(): string { ' | ', array_unique( array_merge( - static::getLocations(), + static::locations(), [ // Location is mandatory to be able to call the operator DirectiveLocation::INPUT_FIELD_DEFINITION, @@ -48,11 +48,22 @@ public static function definition(): string { /** * @return list */ - protected static function getLocations(): array { - return [ + protected static function locations(): array { + return array_merge(static::getLocations(), [ // Locations are required to be able to add operators inside the schema DirectiveLocation::SCALAR, DirectiveLocation::ENUM, + ]); + } + + /** + * @deprecated 6.0.0 Use {@see self::locations()} instead. + * + * @return list + */ + protected static function getLocations(): array { + return [ + // empty ]; } diff --git a/packages/graphql/src/Builder/Directives/OperatorsDirective.php b/packages/graphql/src/Builder/Directives/OperatorsDirective.php index 8675c1405..da51bb90d 100644 --- a/packages/graphql/src/Builder/Directives/OperatorsDirective.php +++ b/packages/graphql/src/Builder/Directives/OperatorsDirective.php @@ -17,7 +17,7 @@ abstract class OperatorsDirective extends ExtendOperatorsDirective { #[Override] public static function definition(): string { $name = DirectiveLocator::directiveName(static::class); - $locations = implode(' | ', array_unique(static::getDirectiveLocations())); + $locations = implode(' | ', array_unique(static::locations())); return <<