Skip to content

Commit

Permalink
Fixed Utf8JsonWriterHelper to not ignore null dictionary values (#6689)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored and michaelstaib committed Nov 21, 2023
1 parent e2732f1 commit 2e3590d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ private static void WriteDictionary(

foreach (var item in dict)
{
if (item.Value is null)
{
continue;
}

writer.WritePropertyName(item.Key);
WriteFieldValue(writer, item.Value);
}
Expand Down
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);
}
}

0 comments on commit 2e3590d

Please sign in to comment.