Surface clearer errors for invalid node IDs#9824
Merged
Merged
Conversation
986c768 to
a07f132
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Relay ID handling by surfacing a more precise runtime error when an [ID] value cannot be formatted due to an incompatible runtime value type, and by adding a Roslyn analyzer to proactively detect conflicting [ID] usages that would otherwise lead to runtime failures.
Changes:
- Introduces
NodeIdInvalidValueExceptionand updates node ID serializers to throw it when formatting fails due to an invalid runtime value type. - Ensures
GraphQLExceptionerrors without a path get the resolver path assigned, which affects non-null propagation error emission (reflected in updated snapshots). - Adds
ConflictingIdAttributeAnalyzer(+ extensive analyzer test coverage and snapshots) and consolidates a moved runtime test.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/test/Types.Tests/Types/Relay/Issue7346Tests.cs | Removes standalone tests (moved into IdAttributeTests). |
| src/HotChocolate/Core/test/Types.Tests/Types/Relay/IdAttributeTests.cs | Adds/relocates runtime tests covering invalid ID formatting and sibling data preservation. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/TestHelper.cs | Registers the new analyzer in the analyzer test harness. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/ConflictingIdAttributeAnalyzerTests.cs | Adds test cases validating analyzer behavior across many type-shape scenarios. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseErrorOnMismatchedMethod_When_IdMethodTypesDiffer.md | Snapshot for analyzer diagnostic on mismatched [ID] method return types. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseErrorOnMismatchedMember_When_IdTypesDiffer.md | Snapshot for analyzer diagnostic on mismatched [ID] member types. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_TaskResultTypesDiffer.md | Snapshot for analyzer diagnostic through Task<T> unwrapping. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_SameTypeNameStringHasMismatchedIdTypes.md | Snapshot for analyzer diagnostic when explicit type-name strings collide. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_SameGenericTypeNameHasMismatchedIdTypes.md | Snapshot for analyzer diagnostic when generic ID type-name keys collide. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_NullableValueTypesDiffer.md | Snapshot for analyzer diagnostic on nullable value type mismatches. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_NestedTaskListElementTypesDiffer.md | Snapshot for analyzer diagnostic through nested task/list unwrapping. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_ListElementTypesDiffer.md | Snapshot for analyzer diagnostic on List<T> element type mismatches. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_InterfaceHasMismatchedIds.md | Snapshot for analyzer diagnostic on interface members with conflicting IDs. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_EnumerableInnerTypesDiffer.md | Snapshot for analyzer diagnostic on IEnumerable<T> inner type mismatches. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_RaiseError_When_ArrayElementTypesDiffer.md | Snapshot for analyzer diagnostic on array element type mismatches. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_ValueTaskResultMatchesScalar.md | Snapshot asserting ValueTask<T> unwrapping compatibility cases. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_TypeNameStringsDiffer.md | Snapshot asserting no diagnostic when explicit type-name strings differ. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_NullableMatchesNonNullable.md | Snapshot asserting nullable/non-nullable compatibility does not trigger diagnostic. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_IdTypesMatch.md | Snapshot asserting no diagnostic when ID runtime types match. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_GenericTypeArgumentsDiffer.md | Snapshot asserting no diagnostic when generic ID type-name keys differ. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_GenericIdAttributeIsUsed.md | Snapshot asserting generic [ID<T>] splits grouping as intended. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_ExplicitTypeNameIsSpecified.md | Snapshot asserting explicit type name avoids conflict diagnostics. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_EnumerableInnerTypesMatch.md | Snapshot asserting enumerable inner types match does not trigger diagnostic. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_EnumerableElementMatchesScalar.md | Snapshot asserting scalar vs enumerable element unwrapping behaves as expected. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_NotRaiseError_When_CollectionShapesShareElementType.md | Snapshot asserting shape differences with same element type do not trigger diagnostic. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_FlagSecondMember_When_NoMemberNamedId.md | Snapshot asserting authoritative-member selection when no Id-named member exists. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/ConflictingIdAttributeAnalyzerTests.Analyze_Should_FlagAllExceptIdMember_When_IdMemberIsNotFirst.md | Snapshot asserting authoritative-member selection prefers member named Id. |
| src/HotChocolate/Core/test/Execution.Tests/Integration/TypeConverter/snapshots/TypeConverterTests.Exception_IsAvailableInErrorFilter_WithQueryConventions_NestedDirectiveInput.snap | Updates expected error output due to path assignment/non-null propagation behavior. |
| src/HotChocolate/Core/test/Execution.Tests/Integration/TypeConverter/snapshots/TypeConverterTests.Exception_IsAvailableInErrorFilter_NestedDirectiveInput.snap | Updates expected error output due to path assignment/non-null propagation behavior. |
| src/HotChocolate/Core/test/Execution.Tests/Integration/TypeConverter/snapshots/TypeConverterTests.Exception_IsAvailableInErrorFilter_Mutation_WithMutationConventions_NestedDirectiveInput.snap | Updates expected error output due to path assignment/non-null propagation behavior. |
| src/HotChocolate/Core/test/Execution.Tests/Integration/TypeConverter/snapshots/TypeConverterTests.Exception_IsAvailableInErrorFilter_Mutation_NestedDirectiveInput.snap | Updates expected error output due to path assignment/non-null propagation behavior. |
| src/HotChocolate/Core/src/Types/Types/Relay/Serialization/OptimizedNodeIdSerializer.cs | Throws NodeIdInvalidValueException for invalid runtime ID value formatting. |
| src/HotChocolate/Core/src/Types/Types/Relay/Serialization/DefaultNodeIdSerializer.cs | Throws NodeIdInvalidValueException for invalid runtime ID value formatting. |
| src/HotChocolate/Core/src/Types/Execution/Extensions/OperationContextExtensions.cs | Ensures GraphQLException errors without a path get the resolver path applied. |
| src/HotChocolate/Core/src/Types.Analyzers/WellKnownAttributes.cs | Adds well-known constants for [ID] attributes. |
| src/HotChocolate/Core/src/Types.Analyzers/Properties/SourceGenResources.resx | Adds localized message template for the new analyzer diagnostic. |
| src/HotChocolate/Core/src/Types.Analyzers/Properties/SourceGenResources.Designer.cs | Adds strongly-typed accessor for the new localized resource. |
| src/HotChocolate/Core/src/Types.Analyzers/Errors.cs | Adds HC0115 diagnostic descriptor for conflicting [ID] attribute types. |
| src/HotChocolate/Core/src/Types.Analyzers/ConflictingIdAttributeAnalyzer.cs | New analyzer detecting conflicting [ID] type bindings within a named type. |
| src/HotChocolate/Core/src/Execution.Abstractions/Execution/Relay/NodeIdInvalidValueException.cs | New exception producing a GraphQL error for invalid runtime ID values. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 3, 2026
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.
No description provided.