From 001126d0ddafdd4999c447bfd75fcbe754cc24ea Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 1 Mar 2024 11:22:02 +0100 Subject: [PATCH] Apply suggestions from code review --- CHANGELOG.md | 4 +++- src/Schema/AST/ASTBuilder.php | 5 ++++- tests/Unit/Schema/AST/ASTBuilderTest.php | 14 ++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9bfb724..777313732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ You can find and compare releases at the [GitHub release page](https://github.co ## Unreleased -- Merge directives from Scalar/Enum/Type/Input/Interface extension node into target node. +### Added + +- Merge directives from Scalar/Enum/Type/Input/Interface extension node into target node https://github.com/nuwave/lighthouse/pull/2512 ## v6.33.4 diff --git a/src/Schema/AST/ASTBuilder.php b/src/Schema/AST/ASTBuilder.php index 36cc40e4d..848068616 100644 --- a/src/Schema/AST/ASTBuilder.php +++ b/src/Schema/AST/ASTBuilder.php @@ -217,7 +217,10 @@ protected function missingBaseDefinition(string $typeName, ObjectTypeExtensionNo return "Could not find a base definition {$typeName} of kind {$typeExtension->kind} to extend."; } - protected function assertExtensionMatchesDefinition(ObjectTypeExtensionNode|InputObjectTypeExtensionNode|InterfaceTypeExtensionNode|ScalarTypeExtensionNode|EnumTypeExtensionNode|UnionTypeExtensionNode $extension, ObjectTypeDefinitionNode|InputObjectTypeDefinitionNode|InterfaceTypeDefinitionNode|ScalarTypeDefinitionNode|EnumTypeDefinitionNode|UnionTypeDefinitionNode $definition): void + protected function assertExtensionMatchesDefinition( + ObjectTypeExtensionNode|InputObjectTypeExtensionNode|InterfaceTypeExtensionNode|ScalarTypeExtensionNode|EnumTypeExtensionNode|UnionTypeExtensionNode $extension, + ObjectTypeDefinitionNode|InputObjectTypeDefinitionNode|InterfaceTypeDefinitionNode|ScalarTypeDefinitionNode|EnumTypeDefinitionNode|UnionTypeDefinitionNode $definition, + ): void { if (static::EXTENSION_TO_DEFINITION_CLASS[$extension::class] !== $definition::class) { throw new DefinitionException("The type extension {$extension->name->value} of kind {$extension->kind} can not extend a definition of kind {$definition->kind}."); diff --git a/tests/Unit/Schema/AST/ASTBuilderTest.php b/tests/Unit/Schema/AST/ASTBuilderTest.php index f8a6f9070..046774bc0 100644 --- a/tests/Unit/Schema/AST/ASTBuilderTest.php +++ b/tests/Unit/Schema/AST/ASTBuilderTest.php @@ -18,8 +18,6 @@ use Nuwave\Lighthouse\Schema\RootType; use Tests\TestCase; -use function assert; - final class ASTBuilderTest extends TestCase { protected ASTBuilder $astBuilder; @@ -59,7 +57,7 @@ public function testMergeTypeExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on OBJECT'; + return /** @lang GraphQL */ 'directive @foo repeatable on OBJECT'; } }; @@ -144,7 +142,7 @@ public function testMergeInputExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on INPUT_OBJECT'; + return /** @lang GraphQL */ 'directive @foo repeatable on INPUT_OBJECT'; } }; @@ -196,7 +194,7 @@ public function testMergeInterfaceExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on INTERFACE'; + return /** @lang GraphQL */ 'directive @foo repeatable on INTERFACE'; } }; @@ -225,7 +223,7 @@ public function testMergeScalarExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on SCALAR'; + return /** @lang GraphQL */ 'directive @foo repeatable on SCALAR'; } }; @@ -276,7 +274,7 @@ public function testMergeEnumExtensionDirectives(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on ENUM'; + return /** @lang GraphQL */ 'directive @foo repeatable on ENUM'; } }; @@ -327,7 +325,7 @@ public function testDoesNotAllowExtendingUndefinedScalar(): void $directive = new class() extends BaseDirective { public static function definition(): string { - return /** @lang GraphQL */ 'directive @foo on SCALAR'; + return /** @lang GraphQL */ 'directive @foo repeatable on SCALAR'; } };