Skip to content

Commit

Permalink
Add failing test for ConvertEmptyStringsToNullDirective when used on …
Browse files Browse the repository at this point in the history
…mutation with input type
  • Loading branch information
Dennis Koster committed Sep 6, 2024
1 parent 45e1cbb commit e4a3cfd
Showing 1 changed file with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,93 @@ public function testConvertsEmptyStringToNullWithGlobalFieldMiddleware(): void
],
]);
}

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

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

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

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

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

0 comments on commit e4a3cfd

Please sign in to comment.