Fix variable coercion for expression-based filter fields - #10126
Open
glen-84 wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes variable coercion failures for expression-based filter fields by avoiding registration of the expression return type as the field’s input coercion runtime type, while still preserving the expression return type for predicate construction.
Changes:
- Stop setting
FilterFieldConfiguration.RuntimeTypefrom expression return types during filter field descriptor construction to prevent variable materialization into non-constructible interface types. - Ensure
FilterField.RuntimeTypeis still derived from the expression return type during type completion so expression-based predicates continue to work. - Add an in-memory snapshot test covering filtering a collection-valued expression field via GraphQL variables.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/HotChocolate/Data/test/Data.Filters.InMemory.Tests/QueryableFilterVisitorExpressionTests.cs | Adds a regression test for variable-based filtering against a collection-valued expression field. |
| src/HotChocolate/Data/test/Data.Filters.InMemory.Tests/snapshots/QueryableFilterVisitorExpressionTests.Create_CollectionExpression_WithVariables.snap | Snapshot for the new regression test (match + no-match cases). |
| src/HotChocolate/Data/src/Data/Filters/FilterFieldDescriptor.cs | Removes expression-based assignment of Configuration.RuntimeType to avoid incorrect variable coercion behavior. |
| src/HotChocolate/Data/src/Data/Filters/Fields/FilterField.cs | Restores runtime type derivation for expression fields at completion time to keep predicate building behavior unchanged. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Patch coverage100.0% of changed lines covered (4/4)
Project coverage: 53.8% (231323/430064 lines) |
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.
Summary
descriptor.Field(x => x.Bars.OrderByDescending(b => b.Id).Take(1))) registered the expression's return type as the field's input coercion runtime type. When the filter was supplied through a GraphQL variable, variable coercion tried to materialize the filter value into that type and failed for non-constructible types such as collection interfaces, rejecting the request withHC0016: Variable 'where' got an invalid value.Test plan
Create_CollectionExpression_WithVariablessnapshot test: a collection-valued expression field filtered through a variable, asserting matching and non-matching results.Closes #7024
Supersedes #9266