Skip to content

Commit

Permalink
Fixed incorrect TotalCount when no data is returned (#7671)
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Nov 4, 2024
1 parent c779f17 commit 69fe81a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public async ValueTask<CursorPaginationData<TEntity>> QueryAsync(
{
var originalQuery = executable.Source;
var combinedQuery = slicedQuery.Select(t => new { TotalCount = originalQuery.Count(), Item = t });
totalCount = 0;

var index = offset;
await foreach (var item in executable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class SqlCursorPagingIntegrationTests : SqlLiteCursorTestBase
new TestData(Guid.NewGuid(), "D"),
];

public TestData[] EmptyData => [];

[Fact]
public async Task Simple_StringList_Default_Items()
{
Expand Down Expand Up @@ -342,6 +344,27 @@ public async Task Nodes_And_TotalCount()
result.MatchSnapshot();
}

[Fact]
public async Task Nodes_And_TotalCount_EmptyData()
{
// arrange
var executor = CreateSchema(EmptyData);

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

// assert
result.MatchSnapshot();
}

[Fact]
public async Task TotalCount_Should_Be_Correct()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": {
"root": {
"nodes": [],
"totalCount": 0
}
}
}

0 comments on commit 69fe81a

Please sign in to comment.