From 911e561df2cc05698920e2cd826d7cc153ded653 Mon Sep 17 00:00:00 2001 From: Hans Krogh Thomsen Date: Sat, 21 Mar 2026 19:33:19 +0100 Subject: [PATCH 1/3] fix(PageConnection): fallback to 0, not -1 on empty pages --- .../src/Types.CursorPagination.Extensions/PageConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs b/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs index 17b074eb0d2..d561d811fbf 100644 --- a/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs +++ b/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs @@ -76,5 +76,5 @@ public override IReadOnlyList>? Edges /// Identifies the total count of items in the connection. /// [GraphQLDescription("Identifies the total count of items in the connection.")] - public int TotalCount => _page.TotalCount ?? -1; + public int TotalCount => _page.TotalCount ?? 0; } From 6a34df9450762b9f0193ddfc8323e83ff6362edc Mon Sep 17 00:00:00 2001 From: Hans Krogh Thomsen Date: Sat, 21 Mar 2026 20:55:14 +0100 Subject: [PATCH 2/3] Update src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/Types.CursorPagination.Extensions/PageConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs b/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs index d561d811fbf..ea92795bfc9 100644 --- a/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs +++ b/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs @@ -76,5 +76,5 @@ public override IReadOnlyList>? Edges /// Identifies the total count of items in the connection. /// [GraphQLDescription("Identifies the total count of items in the connection.")] - public int TotalCount => _page.TotalCount ?? 0; + public int TotalCount => _page.TotalCount ?? _page.Count; } From d3fbe725a1085a0a6a526041fa1d028698e461f3 Mon Sep 17 00:00:00 2001 From: Hans Krogh Thomsen Date: Sun, 22 Mar 2026 10:36:10 +0100 Subject: [PATCH 3/3] fix(PageConnection): throw exception for unavailable total count --- .../src/GreenDonut.Data.Primitives/ValueCursorPage.cs | 2 +- .../src/Types.CursorPagination.Extensions/PageConnection.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GreenDonut/src/GreenDonut.Data.Primitives/ValueCursorPage.cs b/src/GreenDonut/src/GreenDonut.Data.Primitives/ValueCursorPage.cs index 33e4454f6a8..4f50eeaca56 100644 --- a/src/GreenDonut/src/GreenDonut.Data.Primitives/ValueCursorPage.cs +++ b/src/GreenDonut/src/GreenDonut.Data.Primitives/ValueCursorPage.cs @@ -45,7 +45,7 @@ public ValueCursorPage( /// /// An empty page. /// - public static new ValueCursorPage Empty { get; } = new([], false, false, _ => string.Empty); + public static new ValueCursorPage Empty { get; } = new([], false, false, _ => string.Empty, 0); protected override string CreateCursor(int index, int offset, int pageIndex, int totalCount) => _createCursor(new EdgeEntry(Entries[index].Item, offset, pageIndex, totalCount)); diff --git a/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs b/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs index ea92795bfc9..71187812842 100644 --- a/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs +++ b/src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs @@ -76,5 +76,6 @@ public override IReadOnlyList>? Edges /// Identifies the total count of items in the connection. /// [GraphQLDescription("Identifies the total count of items in the connection.")] - public int TotalCount => _page.TotalCount ?? _page.Count; + public int TotalCount => + _page.TotalCount ?? throw new GraphQLException("Total count is not available for this connection."); }