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 <<