Skip to content

TotalCount returns incorrect value -1 instead of 0 #8564

Description

@nZeus

Product

Hot Chocolate

Version

15.1.8.0

Link to minimal reproduction

Steps to reproduce

Hello, today I noticed a small issue related to the totalCount field.

E.g. I have a simple query like

query Q {
	myEntititesQuery() {
		totalCount
		nodes {
			...
		}
	}
}

ant imagine that EF returns 0 records from the DB.

What is expected?

It is expected to have totalCount == 0

What is actually happening?

For some reason totalCount is equal to -1.
I guess it's related to the implementation here - https://github.com/ChilliCream/graphql-platform/blob/8f1394dd60d93faaa4e842a41b38f0961e629562/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Extensions/PagingQueryableExtensions.cs#L194C1-L198C1 - it doesn't set the totalCount in case no entries were returned.

Relevant log output

Additional context

P.S. I use [UseConnection] if it matters

Activity

  1. added theissue type on Aug 18, 2025
  2. changed the issue type fromtoon Aug 20, 2025
  3. michaelstaib commented on Aug 20, 2025

    @michaelstaib
    Member

    Have you enabled total count? Its opt in.

  4. nZeus commented on Aug 26, 2025

    @nZeus
    Author

    Sorry, I missed notifications that you replied.
    Yes, Total Count is enabled:

    Image Image

    I think there is a bug in the library, could you consider to reopen the issue please?

  5. nZeus commented on Aug 29, 2025

    @nZeus
    Author

    @michaelstaib can we reopen this issue, please?

  6. michaelstaib commented on Aug 29, 2025

    @michaelstaib
    Member

    Can you post the full resolver code?

  7. nZeus commented on Sep 1, 2025

    @nZeus
    Author
        [PublicAPI]
        [UseConnection(IncludeTotalCount = true)] 
        [UseFiltering<FilterInputType>]
        [UseSorting<SortInputType>]
        public static async ValueTask<PageConnection<Entity>> GetCategories(
            PagingArguments pagingArguments,
            QueryContext<Entity> queryContext,
            MainDbContext dbContext,
            CancellationToken cancellationToken)
        {
            return await dbContext.Store.Categories
                .With(queryContext.OrderBy(CursorSorting))
                .ToPageConnectionAsync(pagingArguments, cancellationToken);
        }
    
    ..
        internal static readonly Func<SortDefinition<Entity>, SortDefinition<Entity>>? CursorSorting =
            sortDefinition => sortDefinition
                .IfEmpty(d => d
                    .AddAscending(c => c.Name))
                .AddAscending(c => c.Id);
    ..
        public static async ValueTask<PageConnection<T>> ToPageConnectionAsync<T>(
            this IQueryable<T> queryable,
            PagingArguments pagingArguments,
            int maxRelativeCursorCount = DefaultMaxRelativeCursorCount,
            CancellationToken cancellationToken = default)
        {
            return new PageConnection<T>(
                page: await queryable.ToPageAsync(pagingArguments, cancellationToken),
                maxRelativeCursorCount);
        }
  8. added
    Area: DataIssue is related to filtering, sorting, pagination or projections
    on Feb 19, 2026
  9. kapiljaveri commented on Sep 24, 2026

    @kapiljaveri

    Hi @michaelstaib, would it be possible to backport this fix into v15 as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: DataIssue is related to filtering, sorting, pagination or projections🌶️ hot chocolate

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions