-
-
Notifications
You must be signed in to change notification settings - Fork 799
Fix breaking change to IResolverContext.Selection
in HotChocolate v14+ impacting classic projection
#8349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix breaking change to IResolverContext.Selection
in HotChocolate v14+ impacting classic projection
#8349
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix must have a test showing the issue and proving the fix.
@francisphn can you provide a test for this that would fail if this fix is not done? |
I have moved this to the next patch release. |
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.Selection
has had a rewrite and thus impactingQueryableProjectionProvider.cs
which callscontext.Selection.Type.UnwrapRuntimeType()
. Whereascontext.Selection.Type.UnwrapRuntimeType()
would returnBook
in 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.