Skip to content

Commit 3b80da6

Browse files
Fix #8714: @stream fails when list contains fewer items than initialCount (#8715)
1 parent 1529d93 commit 3b80da6

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/HotChocolate/Core/src/Execution/Processing/Tasks/ResolverTask.Execute.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Runtime.InteropServices;
21
using HotChocolate.Execution.Internal;
32
using HotChocolate.Types;
43
using Microsoft.Extensions.DependencyInjection;
4+
using System.Runtime.InteropServices;
55

66
namespace HotChocolate.Execution.Processing.Tasks;
77

@@ -185,7 +185,10 @@ private async ValueTask ExecuteResolverPipelineAsync(CancellationToken cancellat
185185
{
186186
count++;
187187
next = await enumerator.MoveNextAsync().ConfigureAwait(false);
188-
list.Add(enumerator.Current);
188+
if (next)
189+
{
190+
list.Add(enumerator.Current);
191+
}
189192

190193
if (count >= initialCount)
191194
{

src/HotChocolate/Core/test/Execution.Tests/StreamTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ persons @stream(initialCount: 1) {
7676
Assert.IsType<ResponseStream>(result).MatchSnapshot();
7777
}
7878

79+
[LocalFact]
80+
public async Task Stream_InitialCount_Exceeds_Total_Count()
81+
{
82+
// arrange
83+
var executor = await DeferAndStreamTestSchema.CreateAsync();
84+
85+
// act
86+
var result = await executor.ExecuteAsync(
87+
@"{
88+
... @defer {
89+
wait(m: 300)
90+
}
91+
persons @stream(initialCount: 7) {
92+
id
93+
}
94+
}");
95+
96+
Assert.IsType<ResponseStream>(result).MatchSnapshot();
97+
}
98+
7999
[LocalFact]
80100
public async Task Stream_Label_Set_To_abc()
81101
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"data": {
3+
"persons": [
4+
{
5+
"id": "UGVyc29uOjE="
6+
},
7+
{
8+
"id": "UGVyc29uOjI="
9+
},
10+
{
11+
"id": "UGVyc29uOjM="
12+
},
13+
{
14+
"id": "UGVyc29uOjQ="
15+
}
16+
],
17+
"wait": true
18+
}
19+
}

0 commit comments

Comments
 (0)