Repository navigation
Fix source generator edge type for connections in referenced assemblies - #10298
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes a HotChocolate Types source generator edge-case where connection Edges fields were bound to an invalid edge CLR type when the connection/edge runtime types come from a referenced assembly, causing generated code to fail compilation. It also extends the analyzer test infrastructure to compile and reference an additional in-memory assembly, allowing coverage of cross-assembly symbol-binding scenarios.
Changes:
- Fix connection type transformation to use the generated edge GraphQL type wrapper name (e.g.,
AuthorEdgeType) instead of the runtime edge symbol name when buildingConnectionTypeInfo. - Add
TestHelper.CreateReferenceand aGetGeneratedSourceSnapshotoverload that accepts additionalMetadataReferences. - Add new paging snapshot tests covering
PageConnection<T>andConnectionBase<...>cases where the connection/edge types live in a referenced assembly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/test/Types.Analyzers.Tests/TestHelper.cs | Centralizes baseline Roslyn references, adds in-memory referenced-assembly compilation, and allows passing extra metadata references into snapshot generation. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/PagingTests.cs | Adds new snapshot tests that reproduce and validate the cross-assembly paging/edge binding scenario. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/PagingTests.GenerateSource_Inherit_From_PageConnection_In_Referenced_Assembly.md | New snapshot validating correct edge wrapper binding for a PageConnection<T> subclass in a referenced assembly. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/PagingTests.GenerateSource_Inherit_From_ConnectionBase_PageEdge_In_Referenced_Assembly.md | New snapshot validating correct edge wrapper binding for ConnectionBase<...> with a PageEdge<T> subclass in a referenced assembly. |
| src/HotChocolate/Core/src/Types.Analyzers/Inspectors/ConnectionTypeTransformer.cs | Corrects edge type name propagation by using edgeTypeInfo.Name when creating ConnectionTypeInfo in the non-generic connection branch. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Patch coverage100.0% of changed lines covered (1/1)
Project coverage: 56.3% (265116/470693 lines) |
Summary
Edgesfield to the generated edge type (for exampleAuthorEdgeType) when the connection class is declared in a referenced assembly. Previously it emitted the bare runtime symbol name (PageEdge, or a customPageEdge<T>subclass), which produced generated code that did not compile (CS0234 / CS0311).TestHelpergainsCreateReferenceand aGetGeneratedSourceSnapshotoverload that accepts additional metadata references, so analyzer tests can place types in a separate assembly.Test plan
PagingTestssnapshot tests for aPageConnection<T>subclass and for aConnectionBaseconnection with aPageEdge<T>subclass, both declared in a referenced assemblyHotChocolate.Types.Analyzers.Testsproject passes (339 tests, net10.0)Closes #10141