fix(strawberry-shake): generate compilable upload mappers for multiple Upload fields#14
Open
cliedeman wants to merge 1 commit into
Open
fix(strawberry-shake): generate compilable upload mappers for multiple Upload fields#14cliedeman wants to merge 1 commit into
cliedeman wants to merge 1 commit into
Conversation
…e Upload fields
StrawberryShake emitted invalid C# whenever a type or operation involved
more than one Upload-typed field. Two defects in the file-mapper generator
combined to break compilation:
1. The pattern variable in the `Upload` scalar mapper was hardcoded to `u`,
so an input type with several Upload fields produced multiple
`value is Upload u ? u : null` statements in one method scope, yielding
CS0128 ("a local variable named 'u' is already defined").
2. The recursive descent in `AddMapFilesOfInputTypeMethod` had no dedup
guard, so when one input type had multiple fields of the same nested
upload input type the `MapFilesFromType<T>` method was emitted twice
("already defines a member 'MapFilesFromType...'").
The dedup `HashSet` is now threaded through the recursion and the scalar
mapper reuses the already-unique `checkedVariable` name, so every upload
field gets a unique local and each nested mapper is generated once.
Adds a dedicated test class covering both an input type with multiple
Upload scalar fields and an input type with multiple fields of the same
nested upload input type; the generator output is Roslyn-compiled by the
test helper, so both regressions are caught.
Fixes ChilliCream#9559
Fixes ChilliCream#7852
10 tasks
cliedeman
force-pushed
the
fix/ss-upload-duplicate-members
branch
from
June 27, 2026 14:34
37bfe50 to
3999414
Compare
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.
Problem
StrawberryShake generated invalid C# whenever a type or operation involved more than one
Upload-typed field. The generated client failed to compile, which two upstream issues report:Type 'CreateTaskMutation' already defines a member called 'MapFilesFromTypeFileUpload'andA local variable or function named 'u' is already defined in this scope.error CS0128: A local variable or function named 'u' is already defined in this scopefor an input type with twoUploadfields.These are one root-cause area, two distinct defects in
OperationServiceGenerator's file-mapper emission:u. TheUploadscalar mapper hardcoded its pattern variable tou, so an input type with severalUploadfields emitted multiplevalue is Upload u ? u : nullstatements in the same method scope → CS0128.MapFilesFromType<T>member. The recursive descent inAddMapFilesOfInputTypeMethodhad no dedup guard. When one input type had multiple fields of the same nested upload input type (e.g.CreateTaskInput { uploadOne: FileUpload, uploadTwo: FileUpload }), the nested mapper method was generated twice → "already defines a member".Fix
src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp/Generators/OperationServiceGenerator.csHashSet<string>throughAddMapFilesOfInputTypeMethodand move theprocessed.Add(type.Name)guard to the top of that method, so eachMapFilesFromType<T>is emitted exactly once whether reached from a top-level argument or via recursion.upattern variable in the scalarUploadmapper with the already-uniquecheckedVariable(value<Field>_i), so every upload field gets a unique local.The change is equivalent for all existing single-upload cases (variable rename only); the committed snapshots and integration
*.Client.csfiles are updated accordingly.Tests
New dedicated test class
UploadMultipleFilesGeneratorTestswith two cases:Generate_Should_CompileUniqueLocals_When_InputTypeHasMultipleUploadFields— input with twoUploadscalar fields (isolates Strawberry Shake generates invalid C# for mutations with multiple uploads ChilliCream/graphql-platform#7852'sucollision).Generate_Should_EmitSingleMapper_When_InputTypeHasMultipleFieldsOfSameUploadInputType— mirrors the Strawberry shake generating duplicate members when multiple File Inputs exist on the same type ChilliCream/graphql-platform#9559 repro structure (CreateTaskInputwith twoFileUploadfields, eachFileUploadwith twoUploadfields), reproducing both the duplicate member and theucollision.GeneratorTestHelper.AssertResultRoslyn-compiles the generated output, so both defects surface as real compile errors.Before (RED):
After (GREEN): full
StrawberryShake.CodeGeneration.CSharp.Testsproject passes — 191 passed, 1 skipped (pre-existing), 0 failed.Fixes ChilliCream#9559
Fixes ChilliCream#7852
— Claude
🤖 Generated with Claude Code