Skip to content

Cannot use UseProjection with UseConnection and PageConnection<T> #8278

Closed
@mathieu-radyo

Description

@mathieu-radyo

Product

Hot Chocolate

Version

15.1.3

Link to minimal reproduction

https://github.com/mathieu-radyo/HotChocolate-IssueReproductions

Steps to reproduce

  1. Create a GraphQL query using [UseConnection], [UseFiltering], [UseSorting] and [UseProjection] on a resolver that returns PageConnection<T>.
  2. Try to query a parent entity and its related children (e.g. countries and their cities).
  3. Run the query via GraphQL Playground or Studio.

Example code:

[UseConnection]
[UseProjection]
[UseFiltering]
[UseSorting]
public static async Task<PageConnection<Country>> GetCountriesAsync(
    [Service] WorldContext context,
    PagingArguments pagingArguments,
    QueryContext<Country> query,
    CancellationToken cancellationToken = default)
{
    var page = await context.Countries.AsNoTracking()
        .With(query, c => c.IfEmpty(i => i.AddAscending(e => e.Id)))
        .ToPageAsync(pagingArguments, cancellationToken);

    return new PageConnection<Country>(page);
}

GraphQL query used:

query {
  countries(first: 5) {
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
      forwardCursors {
        page
        cursor
      }
      backwardCursors {
        page
        cursor
      }
    }
    nodes {
      id
      name
      emoji
      emojiU
      capital
      cities {
        name
        wikiDataId
      }
    }
    edges {
      cursor
    }
    totalCount
  }
}

What is expected?

I expect to be able to combine [UseConnection] with [UseProjection] to:

  • Benefit from relative cursor-based pagination (forwardCursors, backwardCursors)
  • Apply filtering, sorting, and projection
  • Fetch related child entities like cities without overfetching

What is actually happening?

  • The query fails at startup or runtime with the following error:

    System.ArgumentException: Type 'HotChocolate.Types.Pagination.PageConnection`1[...]' does not have a default constructor (Parameter 'type')
    
  • If I remove [UseProjection], the query runs — but child entities like cities are no longer included, even if defined in the GraphQL schema.

Relevant log output

Additional context

The issue is reproducible in this minimal GitHub repo:
🔗 https://github.com/mathieu-radyo/HotChocolate-IssueReproductions

Questions:

  • Is this limitation expected?
  • Will UseProjection eventually support PageConnection<T>?
  • Is there a recommended workaround to get child entities with relative cursors?

Thanks in advance for your help and your work on this great library!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions