-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Utf8JsonWriterHelper to not ignore null dictionary values
This would avoid sending any null values from StrawberryShake in such a way that if you wanted to set a null value on a request, you could not. They will always come back as unassigned.
- Loading branch information
1 parent
0f7c4a8
commit 3fbcbb7
Showing
2 changed files
with
43 additions
and
4 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
37 changes: 37 additions & 0 deletions
37
src/HotChocolate/AspNetCore/test/Transport.Http.Tests/OperationRequestTests.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,37 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using CookieCrumble; | ||
using Moq; | ||
|
||
namespace HotChocolate.Transport.Http.Tests; | ||
|
||
public class OperationRequestTests | ||
{ | ||
[Fact] | ||
public async Task Should_WriteNullValues() | ||
{ | ||
// arrange | ||
var request = new OperationRequest( | ||
null, | ||
"abc", | ||
"myOperation", | ||
variables: new Dictionary<string, object?>() | ||
{ | ||
["abc"] = "def", | ||
["hij"] = null | ||
}); | ||
|
||
using var memory = new MemoryStream(); | ||
await using var writer = new Utf8JsonWriter(memory); | ||
|
||
// act | ||
request.WriteTo(writer); | ||
await writer.FlushAsync(); | ||
|
||
// assert | ||
var result = Encoding.UTF8.GetString(memory.ToArray()); | ||
Assert.Equal( | ||
"""{"id":"abc","operationName":"myOperation","variables":{"abc":"def","hij":null}}""", | ||
result); | ||
} | ||
} |