Skip to content

Commit

Permalink
refactor(graphql)!: Removed Operator::getDirectiveName() (not neede…
Browse files Browse the repository at this point in the history
…d/used anymore).
  • Loading branch information
LastDragon-ru committed Aug 15, 2023
1 parent 18e565f commit 85ecda3
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 49 deletions.
9 changes: 0 additions & 9 deletions packages/graphql/src/Builder/Contracts/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ interface Operator extends Directive {
*/
public static function getName(): string;

/**
* Must start with `@` and be a valid GraphQL Directive name.
*
* @deprecated 4.1.0 Directive name will be determined by a class name same
* as Lighthouse does. So the method is not needed anymore and will be
* removed in the next major version.
*/
public static function getDirectiveName(): string;

public function getFieldType(TypeProvider $provider, TypeSource $source): string;

public function getFieldDescription(): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ public function __construct() {
}

public static function definition(): string {
$name = static::getDirectiveName() ?: '@'.DirectiveLocator::directiveName(static::class);
$name = '@'.DirectiveLocator::directiveName(static::class);
$locations = implode('|', static::getDirectiveLocations());

return <<<GraphQL
directive {$name} on {$locations}
GraphQL;
}

public static function getDirectiveName(): string {
return '';
}

/**
* @return non-empty-list<string>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LastDragon_ru\LaraASP\GraphQL\Builder\Directives;

use GraphQL\Language\DirectiveLocation;
use Nuwave\Lighthouse\Schema\DirectiveLocator;
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;

use function assert;
Expand All @@ -15,7 +16,7 @@ public function __construct() {
}

public static function definition(): string {
$name = static::getDirectiveName();
$name = '@'.DirectiveLocator::directiveName(static::class);
$locations = implode(' | ', static::getDirectiveLocations());

return <<<GraphQL
Expand All @@ -26,11 +27,6 @@ public static function definition(): string {
GraphQL;
}

/**
* Must start with `@` and be a valid GraphQL Directive name.
*/
abstract protected static function getDirectiveName(): string;

/**
* @return non-empty-list<string>
*/
Expand Down
16 changes: 1 addition & 15 deletions packages/graphql/src/Builder/ManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,14 @@ public static function dataProviderGetPlaceholderTypeDefinitionNode(): array {
* @noinspection PhpMultipleClassesDeclarationsInOneFile
*/
class ManipulatorTest_Operators extends OperatorsDirective implements Scope {
protected static function getDirectiveName(): string {
return '@operators';
}
// empty
}

/**
* @internal
* @noinspection PhpMultipleClassesDeclarationsInOneFile
*/
class ManipulatorTest_OperatorA extends OperatorDirective implements Operator, Scope {
public static function getDirectiveName(): string {
return 'aOperator';
}

public static function getName(): string {
return 'a';
}
Expand All @@ -381,10 +375,6 @@ public function call(Handler $handler, object $builder, Property $property, Argu
* @noinspection PhpMultipleClassesDeclarationsInOneFile
*/
class ManipulatorTest_OperatorB extends OperatorDirective implements Operator {
public static function getDirectiveName(): string {
return 'bOperator';
}

public static function getName(): string {
return 'b';
}
Expand All @@ -411,10 +401,6 @@ public function call(Handler $handler, object $builder, Property $property, Argu
* @noinspection PhpMultipleClassesDeclarationsInOneFile
*/
class ManipulatorTest_OperatorC extends OperatorDirective implements Operator {
public static function getDirectiveName(): string {
return 'cOperator';
}

public static function getName(): string {
return 'c';
}
Expand Down
4 changes: 0 additions & 4 deletions packages/graphql/src/Builder/OperatorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ public static function getName(): string {
throw new Exception('Should not be called');
}

public static function getDirectiveName(): string {
throw new Exception('Should not be called');
}

public function getFieldType(TypeProvider $provider, TypeSource $source): string {
throw new Exception('Should not be called');
}
Expand Down
4 changes: 0 additions & 4 deletions packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,6 @@ public function getFieldDescription(): string {
return 'Custom condition.';
}

public static function getDirectiveName(): string {
throw new Exception('should not be called');
}

public static function definition(): string {
return <<<'GraphQL'
directive @customComplexOperator(value: String) on INPUT_FIELD_DEFINITION
Expand Down
7 changes: 1 addition & 6 deletions packages/graphql/src/SearchBy/Directives/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

namespace LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives;

use Illuminate\Support\Str;
use LastDragon_ru\LaraASP\GraphQL\Builder\Directives\OperatorsDirective;
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Contracts\Scope;

use function implode;

class Operators extends OperatorsDirective implements Scope {
protected static function getDirectiveName(): string {
return implode('', ['@', Str::camel(Directive::Name), 'Operators']);
}
// empty
}

0 comments on commit 85ecda3

Please sign in to comment.