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 authored Jul 25, 2024
1 parent eb88dac commit c091948
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/Schema/Factories/ArgumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
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 c091948

Please sign in to comment.