diff --git a/src/HotChocolate/Core/src/Types/Text/Json/ResultDocument.cs b/src/HotChocolate/Core/src/Types/Text/Json/ResultDocument.cs index 173988b8e67..e067e71e72a 100644 --- a/src/HotChocolate/Core/src/Types/Text/Json/ResultDocument.cs +++ b/src/HotChocolate/Core/src/Types/Text/Json/ResultDocument.cs @@ -448,6 +448,11 @@ private ReadOnlySpan ReadRawValue(DbRow row) [MethodImpl(MethodImplOptions.AggressiveInlining)] private ReadOnlySpan ReadLocalData(int location, int size) { + if (size == 0) + { + return []; + } + var startChunkIndex = location / JsonMemory.BufferSize; var offsetInStartChunk = location % JsonMemory.BufferSize; @@ -725,6 +730,11 @@ private void WriteByte(int position, byte value) private void WriteDataCore(int position, ReadOnlySpan data) { + if (data.Length == 0) + { + return; + } + var chunkIndex = position / JsonMemory.BufferSize; var offset = position % JsonMemory.BufferSize; var availableInChunk = JsonMemory.BufferSize - offset; diff --git a/src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs b/src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs index 057214c4e7e..cd9eaa88c87 100644 --- a/src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs +++ b/src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs @@ -931,11 +931,6 @@ public void SetPropertyName(ReadOnlySpan propertyName) { CheckValidInstance(); - if (propertyName.Length == 0) - { - throw new ArgumentNullException(nameof(propertyName)); - } - var encoding = Encoding.UTF8; var requiredBytes = encoding.GetByteCount(propertyName); byte[]? rented = null; @@ -961,11 +956,6 @@ public void SetPropertyName(ReadOnlySpan propertyName) { CheckValidInstance(); - if (propertyName.Length == 0) - { - throw new ArgumentNullException(nameof(propertyName)); - } - _parent.AssignPropertyName(this, propertyName); } diff --git a/src/HotChocolate/Core/test/Types.Tests/Types/Scalars/AnyTypeTests.cs b/src/HotChocolate/Core/test/Types.Tests/Types/Scalars/AnyTypeTests.cs index a527271f011..ff2cfe10a46 100644 --- a/src/HotChocolate/Core/test/Types.Tests/Types/Scalars/AnyTypeTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/Types/Scalars/AnyTypeTests.cs @@ -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() + .Resolve(_ => new Dictionary { [""] = null })) + .AddJsonTypeConverter() + .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() {