Skip to content

Commit

Permalink
Improve validation message when using output types as inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Jul 25, 2024
1 parent eb88dac commit 1bbfbfc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/Schema/Factories/ArgumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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,
Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/Schema/ValidatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace Tests\Integration\Schema;

use GraphQL\Error\InvariantViolation;
use Nuwave\Lighthouse\Schema\Validator as SchemaValidator;
use Tests\TestCase;

final class ValidatorTest extends TestCase
{
public function testOutputTypeUsedAsInput(): void
{
$this->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();
}
}
11 changes: 6 additions & 5 deletions tests/Unit/Http/Middleware/LogGraphQLQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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())
Expand Down

0 comments on commit 1bbfbfc

Please sign in to comment.