Skip to content

Commit

Permalink
deprecate(graphql): *:getDirectiveLocations()/*:getLocations(), p…
Browse files Browse the repository at this point in the history
…lease use `*::locations()` instead.
  • Loading branch information
LastDragon-ru committed Mar 14, 2024
1 parent 8dd0138 commit 224a69a
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Override;

use function array_merge;
use function array_unique;
use function implode;

Expand All @@ -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 <<<GRAPHQL
"""
Expand All @@ -33,10 +34,21 @@ public static function definition(): string {
/**
* @return non-empty-list<string>
*/
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<string>
*/
protected static function getDirectiveLocations(): array {
return [
// empty
];
}

Expand Down
18 changes: 15 additions & 3 deletions packages/graphql/src/Builder/Directives/IgnoredDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Override;

use function array_merge;
use function array_unique;
use function implode;

Expand All @@ -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 <<<GRAPHQL
"""
Expand All @@ -31,14 +32,25 @@ public static function definition(): string {
/**
* @return non-empty-list<string>
*/
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<string>
*/
protected static function getDirectiveLocations(): array {
return [
// empty
];
}
}
17 changes: 14 additions & 3 deletions packages/graphql/src/Builder/Directives/OperatorDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -48,11 +48,22 @@ public static function definition(): string {
/**
* @return list<string>
*/
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<string>
*/
protected static function getLocations(): array {
return [
// empty
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<<GRAPHQL
"""
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Operators/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Child extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
DirectiveLocation::FIELD_DEFINITION,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Operators/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Condition extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
// empty
];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SearchBy/Operators/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Field extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Logical extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/SortBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ class DirectiveTest__CustomOperatorDirective extends Child {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
return array_merge(parent::getLocations(), [DirectiveLocation::FIELD_DEFINITION]);
protected static function locations(): array {
return array_merge(parent::locations(), [DirectiveLocation::FIELD_DEFINITION]);
}
}
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Operators/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Child extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Operators/Extra/NullsFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Operators/Extra/NullsLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Operators/Extra/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Random extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Operators/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Field extends Operator {
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
DirectiveLocation::SCALAR,
];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/SortBy/Operators/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
* @inheritDoc
*/
#[Override]
protected static function getLocations(): array {
protected static function locations(): array {
return [
// empty
];
Expand Down

0 comments on commit 224a69a

Please sign in to comment.