diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e8cf1928..822d530d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co ## Unreleased +## v6.42.1 + +### Changed + +- Improve validation message when using output types as inputs https://github.com/nuwave/lighthouse/pull/2594 + ## v6.42.0 ### Added diff --git a/src/Schema/Factories/ArgumentFactory.php b/src/Schema/Factories/ArgumentFactory.php index 39ab3dceb..b27ea469c 100644 --- a/src/Schema/Factories/ArgumentFactory.php +++ b/src/Schema/Factories/ArgumentFactory.php @@ -3,7 +3,6 @@ namespace Nuwave\Lighthouse\Schema\Factories; use GraphQL\Language\AST\InputValueDefinitionNode; -use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\Type; use Illuminate\Container\Container; use Nuwave\Lighthouse\Schema\AST\ASTHelper; @@ -46,7 +45,6 @@ public function convert(InputValueDefinitionNode $definitionNode): array { $definitionNodeConverter = Container::getInstance()->make(ExecutableTypeNodeConverter::class); $type = $definitionNodeConverter->convert($definitionNode->type); - assert($type instanceof Type && $type instanceof InputType); $config = [ 'name' => $definitionNode->name->value, diff --git a/tests/Integration/Schema/ValidatorTest.php b/tests/Integration/Schema/ValidatorTest.php new file mode 100644 index 000000000..c75969b25 --- /dev/null +++ b/tests/Integration/Schema/ValidatorTest.php @@ -0,0 +1,28 @@ +schema = /** @lang GraphQL */ ' + type Query { + foo(foo: Foo): Int + } + + type Foo { + foo: Int + } + '; + + $schemaValidator = $this->app->make(SchemaValidator::class); + + $this->expectExceptionObject(new InvariantViolation('The type of Query.foo(foo:) must be Input Type but got: Foo.')); + $schemaValidator->validate(); + } +} diff --git a/tests/Unit/Http/Middleware/LogGraphQLQueriesTest.php b/tests/Unit/Http/Middleware/LogGraphQLQueriesTest.php index 9c6bea956..e25ce3a8d 100644 --- a/tests/Unit/Http/Middleware/LogGraphQLQueriesTest.php +++ b/tests/Unit/Http/Middleware/LogGraphQLQueriesTest.php @@ -4,13 +4,14 @@ use Illuminate\Contracts\Config\Repository as ConfigRepository; use Nuwave\Lighthouse\Http\Middleware\LogGraphQLQueries; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Tests\TestCase; final class LogGraphQLQueriesTest extends TestCase { /** @var \PHPUnit\Framework\MockObject\MockObject&\Psr\Log\LoggerInterface */ - protected $logger; + protected MockObject $logger; protected function getEnvironmentSetUp($app): void { @@ -28,10 +29,10 @@ protected function getEnvironmentSetUp($app): void public function testLogsEveryQuery(): void { $query = /** @lang GraphQL */ <<<'GRAPHQL' -{ - foo -} -GRAPHQL; + { + foo + } + GRAPHQL; $this->logger ->expects($this->once())