Fix IList<T> misclassified as interface on mutation error types#9743
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a schema-build failure in mutation conventions where CLR collection types on mutation error objects (e.g., IList<T>, arrays) could be incorrectly forwarded into type discovery and registered as GraphQL interfaces, leading to strict validation errors (and in some cases earlier crashes).
Changes:
- Unwraps
IsArrayOrListruntime type references to their element type before schema type inference/registration inMutationConventionTypeInterceptor. - Adds a regression test ensuring an error type with an
IList<int>member is treated as a GraphQL list ([Int!]!) and does not register spurious interface types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/HotChocolate/Core/src/Types.Mutations/MutationConventionTypeInterceptor.cs | Unwraps list/array runtime type references before calling schema type inference to avoid misclassification as interfaces. |
| src/HotChocolate/Core/test/Types.Mutations.Tests/AnnotationBasedMutations.cs | Adds regression coverage for IList<int> on error types to ensure correct list handling and prevent accidental interface registration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Schema build for a mutation using
FieldResult<TResult, TError>fails when the error type has a member typed as an array or collection interface (int[],IList<T>,ICollection<T>,IEnumerable<T>,IReadOnlyList<T>, ...).MutationConventionTypeInterceptor.EnsureTypeReferenceRegisteredpassed those raw to the type-discovery pipeline. ForIList<int>,TypeDiscoveryInfo.IsInterfacewas set fromTypeAttributes.Interfaceand the type got registered asInterfaceType<IList<Int32>>, surfacing asThere is no object type implementing interface `ListOfInt32`under strict validation. Forint[], the same path crashed earlier withArgumentNullExceptioninTryRegisterType.The fix unwraps
IsArrayOrListreferences to theirElementTypebefore inference so the wrapper never reaches the discovery handler. Awhileloop handles nested cases (IList<IList<T>>).Test plan
Error_Type_With_IList_Property_Should_Be_Treated_As_ListinAnnotationBasedMutations.cs— record-shape error type with anIList<int>positional parameter, asserts field type is[Int!]!and no spurious*List*interfaces are registered.IList<int>forint[]was also broken pre-fix and is resolved by the same unwrap.