diff --git a/src/HotChocolate/Core/src/Execution/Processing/ResultHelper.cs b/src/HotChocolate/Core/src/Execution/Processing/ResultHelper.cs index b998802b0a3..8689284bd8f 100644 --- a/src/HotChocolate/Core/src/Execution/Processing/ResultHelper.cs +++ b/src/HotChocolate/Core/src/Execution/Processing/ResultHelper.cs @@ -165,14 +165,13 @@ public IQueryResult BuildResult() while (parent != null) { - if (parent is ResultMap map && - path is NamePathSegment nameSegment) + if (parent is ResultMap map && path is NamePathSegment nameSegment) { - ResultValue value = map.GetValue(nameSegment.Name.Value, out int index); + ResultValue value = map.GetValue(nameSegment.Name.Value, out var index); if (value.IsNullable) { - map.SetValue(index, value.Name, null, true); + map.SetValue(index, value.Name, value: null, isNullable: true); break; } @@ -180,6 +179,7 @@ public IQueryResult BuildResult() { map.RemoveValue(index); } + path = path.Parent; parent = parent.Parent; @@ -193,7 +193,6 @@ public IQueryResult BuildResult() else if (parent is ResultMapList mapList && path is IndexerPathSegment mapListIndexSegment) { - if (mapList.IsNullable) { mapList[mapListIndexSegment.Index] = null; diff --git a/src/HotChocolate/Core/src/Execution/Processing/ResultMap.cs b/src/HotChocolate/Core/src/Execution/Processing/ResultMap.cs index 2ef6e3757ea..aa0ef67fb62 100644 --- a/src/HotChocolate/Core/src/Execution/Processing/ResultMap.cs +++ b/src/HotChocolate/Core/src/Execution/Processing/ResultMap.cs @@ -34,7 +34,7 @@ public ResultMap() { get { - ResultValue value = GetValue(key, out int index); + ResultValue value = GetValue(key, out var index); if (index == -1) { throw new KeyNotFoundException(key); @@ -101,6 +101,8 @@ public ResultValue GetValue(string name, out int index) var length = _capacity; ref ResultValue searchSpace = ref MemoryMarshal.GetReference(_buffer.AsSpan()); + // TODO : There is sometimes an issue with the last item of a batch + /* while (length >= 8) { length -= 8; @@ -136,6 +138,7 @@ public ResultValue GetValue(string name, out int index) i += 4; } + */ while (length > 0) { diff --git a/src/HotChocolate/Core/test/Execution.Tests/Processing/ResultMapTests.cs b/src/HotChocolate/Core/test/Execution.Tests/Processing/ResultMapTests.cs index 70b910dea28..8bff38dfda4 100644 --- a/src/HotChocolate/Core/test/Execution.Tests/Processing/ResultMapTests.cs +++ b/src/HotChocolate/Core/test/Execution.Tests/Processing/ResultMapTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Xunit; @@ -54,15 +55,15 @@ public void GetValue_ValueIsFound(int capacity) var resultMap = new ResultMap(); resultMap.EnsureCapacity(capacity); resultMap.SetValue(0, "abc", "def"); - resultMap.SetValue(1, "def", "def"); - resultMap.SetValue(2, "ghi", "def"); + resultMap.SetValue(capacity / 2, "def", "def"); + resultMap.SetValue(capacity - 1, "ghi", "def"); // act - ResultValue value = resultMap.GetValue("def", out int index); + ResultValue value = resultMap.GetValue("def", out var index); // assert Assert.Equal("def", value.Name); - Assert.Equal(1, index); + Assert.Equal(capacity / 2, index); } [Fact]