Skip to content

Commit 69fe81a

Browse files
authored
Fixed incorrect TotalCount when no data is returned (#7671)
1 parent c779f17 commit 69fe81a

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/HotChocolate/Core/src/Types.CursorPagination/QueryableCursorPagingHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public async ValueTask<CursorPaginationData<TEntity>> QueryAsync(
6767
{
6868
var originalQuery = executable.Source;
6969
var combinedQuery = slicedQuery.Select(t => new { TotalCount = originalQuery.Count(), Item = t });
70+
totalCount = 0;
7071

7172
var index = offset;
7273
await foreach (var item in executable

src/HotChocolate/Data/test/Data.EntityFramework.Tests/SqlCursorCursorPagingIntegrationTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class SqlCursorPagingIntegrationTests : SqlLiteCursorTestBase
1313
new TestData(Guid.NewGuid(), "D"),
1414
];
1515

16+
public TestData[] EmptyData => [];
17+
1618
[Fact]
1719
public async Task Simple_StringList_Default_Items()
1820
{
@@ -342,6 +344,27 @@ public async Task Nodes_And_TotalCount()
342344
result.MatchSnapshot();
343345
}
344346

347+
[Fact]
348+
public async Task Nodes_And_TotalCount_EmptyData()
349+
{
350+
// arrange
351+
var executor = CreateSchema(EmptyData);
352+
353+
// act
354+
var result = await executor.ExecuteAsync(
355+
"""
356+
{
357+
root {
358+
nodes { foo }
359+
totalCount
360+
}
361+
}
362+
""");
363+
364+
// assert
365+
result.MatchSnapshot();
366+
}
367+
345368
[Fact]
346369
public async Task TotalCount_Should_Be_Correct()
347370
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"data": {
3+
"root": {
4+
"nodes": [],
5+
"totalCount": 0
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)