Skip to content

Surface clearer errors for invalid node IDs#9824

Merged
tobias-tengler merged 2 commits into
mainfrom
tte/improve-invalid-node-id-value-error
Jun 3, 2026
Merged

Surface clearer errors for invalid node IDs#9824
tobias-tengler merged 2 commits into
mainfrom
tte/improve-invalid-node-id-value-error

Conversation

@tobias-tengler

Copy link
Copy Markdown
Member

No description provided.

@tobias-tengler tobias-tengler marked this pull request as ready for review June 3, 2026 07:54
Copilot AI review requested due to automatic review settings June 3, 2026 07:54
@tobias-tengler tobias-tengler changed the title Raise proper error for invalid ID types Surface clearer errors for invalid node IDs Jun 3, 2026
@tobias-tengler tobias-tengler force-pushed the tte/improve-invalid-node-id-value-error branch from 986c768 to a07f132 Compare June 3, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 NodeIdInvalidValueException and updates node ID serializers to throw it when formatting fails due to an invalid runtime value type.
  • Ensures GraphQLException errors 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.

@tobias-tengler tobias-tengler merged commit bbe4c54 into main Jun 3, 2026
280 of 282 checks passed
@tobias-tengler tobias-tengler deleted the tte/improve-invalid-node-id-value-error branch June 3, 2026 08:10
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