Implement shared response type classes in GraphQL client generator #9
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.
📝 Description
This PR implements shared response type classes in the GraphQL Kotlin client generator to eliminate duplicate type generation across operations. Previously, when multiple queries used the same GraphQL types, the generator would create separate classes in operation-specific packages (e.g.,
com.example.generated.firstquery.Userandcom.example.generated.secondquery.User). This PR changes the generator to create shared type classes in a common.typespackage when operations select identical fields.Key Changes:
Generator-level type caching: Moved
classNameCache,typeToSelectionSetMap, andenumClassToTypeSpecsfrom context-level to generator-level so they can be shared across all operations during generation.Package structure change: Response types now use
${packageName}.typesinstead of${packageName}.${operationName.lowercase()}, following the same pattern as existing shared types (.inputs,.enums).Enhanced type collection:
.typespackage are collected into shared typesPreserved functionality:
__UNKNOWN_VALUE) are preserved across operationsImpact:
Example:
Before:
After:
🔗 Related Issues
Requested by: @arthurkkp-cog (Arthur Poon)
Link to Devin run: https://app.devin.ai/sessions/46723e01f5414e538819c44c6ee54652
🔍 Review Checklist
Critical areas to review:
Package structure change: This is a breaking change. Verify the new
.typespackage naming is acceptable and aligns with project conventions.Polymorphic type handling: Check the different logic paths for Kotlinx (sealed classes) vs Jackson (separate files). Pay special attention to:
GraphQLClientGenerator.ktlines 203-234Type deduplication correctness: Verify that:
multiple_queriestest case)Enum default values: Check that
__UNKNOWN_VALUEenum defaults are preserved across all operations (seeSecondQuery.kttest data).Test expectations: With 157 test files updated, spot-check a few test cases to ensure expectations match actual generated output:
kotlinx/multiple_queries/*- shared types across queriesgenerator/interface_*- polymorphic typesgenerator/union_*- union type handlingEdge cases: