**Improve handling of duplicate types across schema files to avoid HC…#9836
**Improve handling of duplicate types across schema files to avoid HC…#9836andreashellquist wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves schema loading and type mapping resiliency when working with multiple GraphQL SDL files that may overlap or contain mixed extensions/definitions, and adds tests covering these scenarios.
Changes:
- Deduplicate non-extension schema definitions across multiple documents to avoid duplicate-type errors during schema load.
- Handle scalar registration and mixed extension/definition documents during
SchemaHelper.Load. - Add collision-avoidance logic for generated runtime type names and new unit tests for duplicate/mixed schema inputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs | Adds tests for duplicate type definitions across files and mixed extension+definition documents. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/SchemaHelper.cs | Merges and deduplicates schema definitions across files; changes scalar registration handling. |
| src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.cs | Adds retry logic to avoid runtime type name collisions by appending a numeric suffix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… error diagnostics
michaelstaib
left a comment
There was a problem hiding this comment.
This doesn't really solve the problem and could lead to a plethora of issues.
Thanks for the review. I'm primarily a user of the package who hit this bug directly when trying to use it — I don't have deep knowledge of the codebase architecture, just gave copilot a chance to sort it out. Happy to close this PR if the team prefers to solve it differently. The issue and repro repo are there for reference. I've reverted the TypeDescriptorMapper change. Could you clarify what you see as the proper approach? Should the deduplication happen upstream in the CLI download step, or would you prefer a validation-with-clear-error rather than silent dedup? Happy to adjust |
Summary of Changes
I've identified and fixed the
HC0065bug in StrawberryShake's code generation pipeline. The issue manifested in two main areas.#9837
1.
SchemaHelper.Load— HC0065 Duplicate Type Name FixFile:
src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/SchemaHelper.csRoot Cause
When multiple schema files contain overlapping type definitions (common with Hygraph/CMS schemas where glob patterns may pick up multiple files, or when schemas are split across files),
SchemaHelper.Loadpreviously called:for each non-extension file independently.
This caused the Hot Chocolate type system to register the same type name multiple times, triggering the
HC0065(duplicate type name) error.Additionally, documents that contained both extension nodes and regular type definitions were treated entirely as extension files, causing the regular type definitions in those mixed files to be silently ignored.
Fix
Merge and Deduplicate Type Definitions
All non-extension definitions from all schema files are now merged into a single deduplicated document before calling
builder.AddDocument().TryAdd(...).Correctly Process Mixed Files
Files containing both:
are now processed correctly, ensuring both categories are included.
Deduplicate Scalar Registrations
Added a
HashSet<string>to track already-registered scalars and prevent duplicateAddType(...)calls.Exclude Scalars from the Merged Document
Scalar type definitions are already registered through:
Therefore, scalar definitions are excluded from the merged document to avoid potential registration conflicts.
2.
TypeDescriptorMapper.ExtractRuntimeType— SS0009 Name Collision ResilienceFile:
src/StrawberryShake/CodeGeneration/src/CodeGeneration/Mappers/TypeDescriptorMapper.csRoot Cause
When generated C# output type names collided with existing registered type names (possible in large schemas with many similarly named types), the code would immediately throw a
TypeNameCollision(SS0009) exception.Fix
Instead of failing immediately, the code now attempts alternative names by appending numeric suffixes:
_1_2_3This mirrors the behavior of:
and makes code generation more resilient when working with large or complex schemas.
3. Tests
File:
src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.csAdded Test Cases
Load_DuplicateTypesAcrossFiles_DoesNotThrowHC0065HC0065.Load_MixedExtensionAndDefinitionFile_ProcessesBothResulting Behavior Changes
Duplicate Types Across Schema Files
Before
HC0065.After
Mixed Extension + Definition Files
Before
After
Runtime Type Name Collisions
Before
SS0009.After