Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue with non-null arguments that have defaults (#2441)
- Loading branch information
1 parent
27c68fa
commit 66ced99
Showing
12 changed files
with
230 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/HotChocolate/Core/src/Execution/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/HotChocolate/Core/test/Execution.Tests/Integration/Spec/ArgumentCoercionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Snapshooter.Xunit; | ||
using Xunit; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Execution.Integration.Spec | ||
{ | ||
public class ArgumentCoercionTests | ||
{ | ||
[Fact] | ||
public async Task Pass_In_Null_To_NonNullArgument_With_DefaultValue() | ||
{ | ||
// arrange | ||
IRequestExecutor executor = | ||
await new ServiceCollection() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.BuildRequestExecutorAsync(); | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync("{ sayHello(name: null) }"); | ||
|
||
// assert | ||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public async Task Pass_In_Nothing_To_NonNullArgument_With_DefaultValue() | ||
{ | ||
// arrange | ||
IRequestExecutor executor = | ||
await new ServiceCollection() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.BuildRequestExecutorAsync(); | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync("{ sayHello }"); | ||
|
||
// assert | ||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public async Task Pass_In_Nothing_To_NonNullArgument_With_DefaultValue_By_Variable() | ||
{ | ||
// arrange | ||
IRequestExecutor executor = | ||
await new ServiceCollection() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.BuildRequestExecutorAsync(); | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync( | ||
"query ($a: String!) { sayHello(name: $a) }"); | ||
|
||
// assert | ||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public async Task Pass_In_Null_To_NonNullArgument_With_DefaultValue_By_Variable() | ||
{ | ||
// arrange | ||
IRequestExecutor executor = | ||
await new ServiceCollection() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.BuildRequestExecutorAsync(); | ||
|
||
var variables = new Dictionary<string, object?> { { "a", null } }; | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync( | ||
"query ($a: String!) { sayHello(name: $a) }", | ||
variables); | ||
|
||
// assert | ||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public async Task Pass_In_Sydney_To_NonNullArgument_With_DefaultValue_By_Variable() | ||
{ | ||
// arrange | ||
IRequestExecutor executor = | ||
await new ServiceCollection() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.BuildRequestExecutorAsync(); | ||
|
||
var variables = new Dictionary<string, object?> { { "a", "Sydney" } }; | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync( | ||
"query ($a: String!) { sayHello(name: $a) }", | ||
variables); | ||
|
||
// assert | ||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
public class Query | ||
{ | ||
public string SayHello(string name = "Michael") => $"Hello {name}."; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...apshots__/ArgumentCoercionTests.Pass_In_Nothing_To_NonNullArgument_With_DefaultValue.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"sayHello": "Hello Michael." | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...gumentCoercionTests.Pass_In_Nothing_To_NonNullArgument_With_DefaultValue_By_Variable.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Variable \u0060a\u0060 is required.", | ||
"locations": [ | ||
{ | ||
"line": 1, | ||
"column": 8 | ||
} | ||
], | ||
"extensions": { | ||
"code": "EXEC_NON_NULL_VIOLATION", | ||
"variable": "a" | ||
} | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
..._snapshots__/ArgumentCoercionTests.Pass_In_Null_To_NonNullArgument_With_DefaultValue.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Detected a non-null violation in argument \u0060name\u0060.", | ||
"locations": [ | ||
{ | ||
"line": 1, | ||
"column": 12 | ||
} | ||
], | ||
"extensions": { | ||
"responseName": "sayHello", | ||
"errorPath": [ | ||
"name" | ||
] | ||
} | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
.../ArgumentCoercionTests.Pass_In_Null_To_NonNullArgument_With_DefaultValue_By_Variable.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Variable \u0060a\u0060 is required.", | ||
"locations": [ | ||
{ | ||
"line": 1, | ||
"column": 8 | ||
} | ||
], | ||
"extensions": { | ||
"code": "EXEC_NON_NULL_VIOLATION", | ||
"variable": "a" | ||
} | ||
} | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
...rgumentCoercionTests.Pass_In_Sydney_To_NonNullArgument_With_DefaultValue_By_Variable.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"sayHello": "Hello Sydney." | ||
} | ||
} |