Skip to content

Fix IList<T> misclassified as interface on mutation error types#9743

Merged
glen-84 merged 2 commits into
mainfrom
gai/fix-ilist-on-mutation-error-type
May 19, 2026
Merged

Fix IList<T> misclassified as interface on mutation error types#9743
glen-84 merged 2 commits into
mainfrom
gai/fix-ilist-on-mutation-error-type

Conversation

@glen-84
Copy link
Copy Markdown
Member

@glen-84 glen-84 commented May 19, 2026

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.EnsureTypeReferenceRegistered passed those raw to the type-discovery pipeline. For IList<int>, TypeDiscoveryInfo.IsInterface was set from TypeAttributes.Interface and the type got registered as InterfaceType<IList<Int32>>, surfacing as There is no object type implementing interface `ListOfInt32` under strict validation. For int[], the same path crashed earlier with ArgumentNullException in TryRegisterType.

The fix unwraps IsArrayOrList references to their ElementType before inference so the wrapper never reaches the discovery handler. A while loop handles nested cases (IList<IList<T>>).

Test plan

  • New regression test Error_Type_With_IList_Property_Should_Be_Treated_As_List in AnnotationBasedMutations.cs — record-shape error type with an IList<int> positional parameter, asserts field type is [Int!]! and no spurious *List* interfaces are registered.
  • Empirically verified that swapping the fixture's IList<int> for int[] was also broken pre-fix and is resolved by the same unwrap.
  • Full Mutations test suite green on net8 / net9 / net10 (98/98).

Copilot AI review requested due to automatic review settings May 19, 2026 14:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IsArrayOrList runtime type references to their element type before schema type inference/registration in MutationConventionTypeInterceptor.
  • 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.

Comment thread src/HotChocolate/Core/src/Types.Mutations/MutationConventionTypeInterceptor.cs Outdated
Comment thread src/HotChocolate/Core/test/Types.Mutations.Tests/AnnotationBasedMutations.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@glen-84 glen-84 merged commit bb308a3 into main May 19, 2026
275 of 279 checks passed
@glen-84 glen-84 deleted the gai/fix-ilist-on-mutation-error-type branch May 19, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants