Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two failing tests to reproduce failing ConvertEmptyStringsToNullDirective #2611

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Integration\Schema\Directives;

use Nuwave\Lighthouse\Schema\Directives\ConvertEmptyStringsToNullDirective;
use Tests\TestCase;

final class ConvertEmptyStringsToNullDirectiveTest extends TestCase
Expand Down Expand Up @@ -159,4 +160,65 @@ public function testConvertsNonNullableArgumentsWhenUsedOnArgument(): void
],
]);
}

public function testConvertsEmptyStringToNullWithFieldDirective(): void
{
$this->schema = /** @lang GraphQL */ '
type Query {
foo(bar: String): FooResponse
@convertEmptyStringsToNull
@field(resolver: "Tests\\\Utils\\\Mutations\\\ReturnReceivedInput")
}

type FooResponse {
bar: String
}
';

$this->graphQL(/** @lang GraphQL */ '
{
foo(bar: "") {
bar
}
}
')->assertExactJson([
'data' => [
'foo' => [
'bar' => null,
],
],
]);
}

public function testConvertsEmptyStringToNullWithGlobalFieldMiddleware(): void
{
config(['lighthouse.field_middleware' => [
ConvertEmptyStringsToNullDirective::class,
]]);

$this->schema = /** @lang GraphQL */ '
type Query {
foo(bar: String): FooResponse
@field(resolver: "Tests\\\Utils\\\Mutations\\\ReturnReceivedInput")
}

type FooResponse {
bar: String
}
';

$this->graphQL(/** @lang GraphQL */ '
{
foo(bar: "") {
bar
}
}
')->assertExactJson([
'data' => [
'foo' => [
'bar' => null,
],
],
]);
}
}
16 changes: 16 additions & 0 deletions tests/Utils/Mutations/ReturnReceivedInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Tests\Utils\Mutations;

final class ReturnReceivedInput
{
/**
* @param array<string, mixed> $args
*
* @return array<string, mixed>
*/
public function __invoke(mixed $root, array $args): array
{
return $args;
}
}
Loading