This repository demonstrates an issue when using [UseConnection]
in combination with [UseProjection]
in HotChocolate.
- Clone this repository
- Launch the project (
dotnet run
) - Open GraphQL Playground or Studio
- Run the following query:
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
}
}
The query should return:
- A paginated list of countries using relative cursors
- Associated child entities like
cities
- Proper filtering, sorting, and projection applied
- No overfetching in the database (thanks to projection)
-
With
[UseProjection]
+[UseConnection]
, the application fails with:System.ArgumentException: Type 'HotChocolate.Types.Pagination.PageConnection`1[...]' does not have a default constructor (Parameter 'type')
-
Without
[UseProjection]
, the query works — but child entities likecities
are not fetched, and full objects are retrieved from the database (overfetching).
- Is this a limitation by design?
- Is support for
UseProjection
withPageConnection<T>
planned? - Are there workarounds to get both relative cursors and projection?