Skip to content

fix(strawberry-shake): generate compilable upload mappers for multiple Upload fields#14

Open
cliedeman wants to merge 1 commit into
fork-ci-basefrom
fix/ss-upload-duplicate-members
Open

fix(strawberry-shake): generate compilable upload mappers for multiple Upload fields#14
cliedeman wants to merge 1 commit into
fork-ci-basefrom
fix/ss-upload-duplicate-members

Conversation

@cliedeman

@cliedeman cliedeman commented Jun 27, 2026

Copy link
Copy Markdown

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:

These are one root-cause area, two distinct defects in OperationServiceGenerator's file-mapper emission:

  1. Reused local u. The Upload scalar mapper hardcoded its pattern variable to u, so an input type with several Upload fields emitted multiple value is Upload u ? u : null statements in the same method scope → CS0128.
  2. Duplicate MapFilesFromType<T> member. The recursive descent in AddMapFilesOfInputTypeMethod had 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.cs

  • Thread the dedup HashSet<string> through AddMapFilesOfInputTypeMethod and move the processed.Add(type.Name) guard to the top of that method, so each MapFilesFromType<T> is emitted exactly once whether reached from a top-level argument or via recursion.
  • Replace the hardcoded u pattern variable in the scalar Upload mapper with the already-unique checkedVariable (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.cs files are updated accordingly.

Tests

New dedicated test class UploadMultipleFilesGeneratorTests with two cases:

GeneratorTestHelper.AssertResult Roslyn-compiles the generated output, so both defects surface as real compile errors.

Before (RED):

Type 'TestQuery' already defines a member called 'MapFilesFromTypeFileUpload' with the same parameter types
A local variable or function named 'u' is already defined in this scope

After (GREEN): full StrawberryShake.CodeGeneration.CSharp.Tests project passes — 191 passed, 1 skipped (pre-existing), 0 failed.

Fixes ChilliCream#9559
Fixes ChilliCream#7852

— Claude
🤖 Generated with Claude Code

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants