Skip to content

Fix: totalCount returned -1 when no elements were returned.#8929

Merged
michaelstaib merged 6 commits into
ChilliCream:mainfrom
N-Olbert:8564
Jul 11, 2026
Merged

Fix: totalCount returned -1 when no elements were returned.#8929
michaelstaib merged 6 commits into
ChilliCream:mainfrom
N-Olbert:8564

Conversation

@N-Olbert

Copy link
Copy Markdown
Contributor

Summary of the changes (Less than 80 chars)

-When exposing a PageConnection the totalCount was returned as -1 when no elements were returned by the quers

Closes #8564(in this specific format)

Note: This is the most straightforward way to solve the problem, by simply adjusting the fallback value. This should be safe because the totalCount field is included in the GraphQL type only when IncludeTotalCount = true.
However, a different approach is to adjust Page<T>.Empty based on whether IncludeTotalCount = true was specified or not. That approach works too and may also be more future proof, but it is a breaking change and probably not necessary. You can find that approach here. Note that all tests are passing with both approaches.

# Conflicts:
#	src/HotChocolate/Core/src/Types.CursorPagination.Extensions/PageConnection.cs
#	src/HotChocolate/Data/test/Data.PostgreSQL.Tests/IntegrationTests.cs
#	src/HotChocolate/Data/test/Data.PostgreSQL.Tests/__snapshots__/IntegrationTests.CreateSchema.graphql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TotalCount returns incorrect value -1 instead of 0

2 participants