Skip to content

Disambiguate projection parameters when input argument is named _alias or _projection - #997

Merged
iuliiasobolevska merged 2 commits into
Netflix:masterfrom
mangeshraut712:fix/930-alias-mutation-arg-collision
Nov 3, 2026
Merged

iuliiasobolevska merged 2 commits into
Netflix:masterfrom
mangeshraut712:fix/930-alias-mutation-arg-collision

Conversation

@mangeshraut712

Copy link
Copy Markdown
Contributor

Fixes #930

Root Cause

In Kotlin 2 client generation (GenerateKotlin2ClientTypes.kt), projection methods for complex fields add:

  1. Every input argument defined on the GraphQL field via addInputArgs.
  2. A client-side field alias parameter hardcoded as _alias: String? = null.
  3. A client-side projection lambda parameter hardcoded as _projection: TypeProjection.() -> TypeProjection.

When a GraphQL schema field has an argument named _alias (or _projection), the generated method ends up with two parameters sharing the same identifier, resulting in a Kotlin compilation failure (Conflicting declarations: _alias) as well as ambiguous symbol references when constructing the field(...) call.

Solution

  • When adding the client projection parameters for a field, check the sanitized names of inputValueDefinitions.
  • Disambiguate the alias parameter name (appending trailing underscores, e.g. _alias_) and projection parameter name (_projection_) only if they collide with an input argument on that field.
  • For all existing schemas without colliding arguments, the parameter names remain unchanged (_alias and _projection), preserving full backward compatibility.
  • Added unit tests in Kotlin2CodeGenTest asserting correct code generation and compiling client queries that use _alias and _projection field arguments.

Local Verification

Executed ./gradlew check with OpenJDK 17:

BUILD SUCCESSFUL in 5m 44s
49 actionable tasks: 26 executed, 23 up-to-date

mangeshraut712 and others added 2 commits November 3, 2026 14:16
Handle schema arguments that shadow the inherited serializer.
Reuse KotlinPoet name allocation and parameter references.
Cover runtime aliases, chained collisions, default omission and custom serialization.
Include the local Kotlin type-name regression test.
@iuliiasobolevska
iuliiasobolevska force-pushed the fix/930-alias-mutation-arg-collision branch from a696e59 to fe97230 Compare November 3, 2026 22:39
@iuliiasobolevska

iuliiasobolevska commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @mangeshraut712! Thank you for the contribution! Preserving schema argument names and renaming only colliding generated parameters is the right approach.

I rebased onto master, preserved your commit and added a separate follow-up that:

  • extracts the generated names into constants and uses KotlinPoet’s NameAllocator to remove duplicate collision-handling logic;
  • fixes the related inputValueSerializer shadowing case;
  • adds compilation and runtime coverage for chained collisions and alias rendering.

This will be released in 8.9.0.

@iuliiasobolevska
iuliiasobolevska merged commit d1ab139 into Netflix:master Nov 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_alias in mutation argument breaks compilation

2 participants