Skip to content
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
10 changes: 10 additions & 0 deletions src/HotChocolate/Core/src/Types/Text/Json/ResultDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ private ReadOnlySpan<byte> ReadRawValue(DbRow row)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private ReadOnlySpan<byte> ReadLocalData(int location, int size)
{
if (size == 0)
{
return [];
}

var startChunkIndex = location / JsonMemory.BufferSize;
var offsetInStartChunk = location % JsonMemory.BufferSize;

Expand Down Expand Up @@ -725,6 +730,11 @@ private void WriteByte(int position, byte value)

private void WriteDataCore(int position, ReadOnlySpan<byte> data)
{
if (data.Length == 0)
{
Comment thread
glen-84 marked this conversation as resolved.
return;
}

var chunkIndex = position / JsonMemory.BufferSize;
var offset = position % JsonMemory.BufferSize;
var availableInChunk = JsonMemory.BufferSize - offset;
Expand Down
10 changes: 0 additions & 10 deletions src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,6 @@ public void SetPropertyName(ReadOnlySpan<char> propertyName)
{
CheckValidInstance();

if (propertyName.Length == 0)
{
throw new ArgumentNullException(nameof(propertyName));
}

var encoding = Encoding.UTF8;
var requiredBytes = encoding.GetByteCount(propertyName);
byte[]? rented = null;
Expand All @@ -961,11 +956,6 @@ public void SetPropertyName(ReadOnlySpan<byte> propertyName)
{
CheckValidInstance();

if (propertyName.Length == 0)
{
throw new ArgumentNullException(nameof(propertyName));
}

_parent.AssignPropertyName(this, propertyName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,39 @@ public async Task Output_Return_RecordList()
result.ToJson().MatchSnapshot();
}

[Fact]
public async Task Output_Return_Dictionary_With_Empty_Key()
{
// arrange
var executor =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType(
d => d
.Name("Query")
.Field("foo")
.Type<AnyType>()
.Resolve(_ => new Dictionary<string, object?> { [""] = null }))
.AddJsonTypeConverter()
Comment thread
glen-84 marked this conversation as resolved.
.BuildRequestExecutorAsync();

// act
var result = (await executor.ExecuteAsync("{ foo }")).ExpectOperationResult();

// assert
Assert.Empty(result.Errors);
result.MatchInlineSnapshot(
"""
{
"data": {
"foo": {
"": null
}
}
}
""");
}

[Fact]
public async Task Output_Return_DateTime()
{
Expand Down
Loading