Fix breaking change to IResolverContext.Selection in HotChocolate v14+ impacting classic projection#8349
Draft
francisphn wants to merge 2 commits intoChilliCream:mainfrom
Draft
Conversation
…t instead of type of entity when classic projection is used in conjunction with mutation convention, due to changes introduced to IResolverContext since v14
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a breaking change in the classic projection engine caused by IResolverContext.Selection.Type.UnwrapRuntimeType() returning System.Object in HotChocolate v14+. It replaces the runtime type lookup with the generic type parameter to restore correct projection behavior.
- Replace
context.Selection.Type.UnwrapRuntimeType()withtypeof(TEntityType)inQueryableProjectionProvider. - Ensures the correct entity type is used for projection scopes in v14+.
Comments suppressed due to low confidence (2)
src/HotChocolate/Data/src/Data/Projections/Expressions/QueryableProjectionProvider.cs:110
- [nitpick] Consider adding a brief comment explaining why
typeof(TEntityType)is used here instead of the originalUnwrapRuntimeType()to clarify the workaround for selection type mismatches introduced in v14+.
typeof(TEntityType),
src/HotChocolate/Data/src/Data/Projections/Expressions/QueryableProjectionProvider.cs:107
- Add a unit test that covers the classic projection workflow for a mutation followed by a projection (e.g., with
[UseMutationConvention]and[UseProjection]) to prevent regressions in future HotChocolate versions.
var visitorContext = new QueryableProjectionContext(
michaelstaib
requested changes
Jul 22, 2025
Member
michaelstaib
left a comment
There was a problem hiding this comment.
This fix must have a test showing the issue and proving the fix.
Member
|
@francisphn can you provide a test for this that would fail if this fix is not done? |
Member
|
I have moved this to the next patch release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I came across this when trying to upgrade from v13 to v14 and then to v15. We use
[UseMutationConvention]in tandem with[UseProjection]to refetch the entity being returned from database:We are excited about the new projection engine in v15 but are taking a lift and shift approach first, and I understand the classic projection engine is not considered deprecated in v15.
Debugging reveals that it seems
context.Selectionhas had a rewrite and thus impactingQueryableProjectionProvider.cswhich callscontext.Selection.Type.UnwrapRuntimeType(). Whereascontext.Selection.Type.UnwrapRuntimeType()would returnBookin this case in v13, since v14 it has returnedSystem.Object. This ultimately led to an exception being thrown:I understand it has been a few years since the maintainers have touched this part of HotChocolate. We are short on time but happy to file a bug report with minimal reproduction if that is the expectation before this PR can be considered.