client: shared response types across operations (useSharedResponseTypes opt-in) #10
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
Implements cross-operation type reuse for GraphQL response types, controlled by a new
useSharedResponseTypesconfiguration parameter (default:false). This feature reduces duplicate type generation when multiple GraphQL operations select the same fields from the same GraphQL type.Current behavior (default): Each operation generates response types in its own package (e.g.,
com.example.generated.operation1.User,com.example.generated.operation2.User)New behavior (when enabled): Response types with identical selection sets are shared across operations in a
.responsespackage with numbered variants for different selection sets (e.g.,ComplexObject,ComplexObject2,ComplexObject3)Key implementation changes:
useSharedResponseTypes: Booleanconfig parameter across client generator, Gradle plugin, and Maven pluginsharedResponseTypeSpecs,globalClassNameCache,globalTypeToSelectionSetMap) inGraphQLClientGeneratorthat are conditionally passed toGraphQLClientGeneratorContextgenerateClassName()to route object types to.responsespackage when flag is enabledgenerateTypeName.ktto conditionally store in shared vs per-operation cachesGraphQLClientGenerator.generate()to skip writing shared types in per-operation loop and instead write them once as shared typesTest coverage:
ComplexObjectvariants (ComplexObject, ComplexObject2, ComplexObject3) in.responsespackageBackwards compatibility:
false)🔗 Related Issues
🔍 Reviewer Checklist
generateTypeName.ktcorrectly handleuseSharedResponseTypesflagGraphQLClientGenerator.responsesfollows pattern of.inputs,.enums)false