Skip to content

Conversation

@devin-ai-integration
Copy link

📝 Description

Implements cross-operation type reuse for GraphQL response types, controlled by a new useSharedResponseTypes configuration 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 .responses package with numbered variants for different selection sets (e.g., ComplexObject, ComplexObject2, ComplexObject3)

Key implementation changes:

  • Added useSharedResponseTypes: Boolean config parameter across client generator, Gradle plugin, and Maven plugin
  • Introduced global caches (sharedResponseTypeSpecs, globalClassNameCache, globalTypeToSelectionSetMap) in GraphQLClientGenerator that are conditionally passed to GraphQLClientGeneratorContext
  • Modified generateClassName() to route object types to .responses package when flag is enabled
  • Updated type storage logic in generateTypeName.kt to conditionally store in shared vs per-operation caches
  • Modified GraphQLClientGenerator.generate() to skip writing shared types in per-operation loop and instead write them once as shared types

Test coverage:

  • Added integration test with two operations containing identical selection sets
  • Verified generation of exactly 3 shared ComplexObject variants (ComplexObject, ComplexObject2, ComplexObject3) in .responses package

Backwards compatibility:

  • Feature is opt-in (defaults to false)
  • All existing tests pass
  • No breaking changes to existing behavior

🔗 Related Issues

🔍 Reviewer Checklist

  • Verify all conditional logic paths in generateTypeName.kt correctly handle useSharedResponseTypes flag
  • Confirm global cache initialization and lifecycle are correct in GraphQLClientGenerator
  • Review package naming consistency (.responses follows pattern of .inputs, .enums)
  • Verify backwards compatibility - default behavior unchanged when flag is false
  • Consider whether test coverage is sufficient (currently one integration test for happy path)
  • Check handling of edge cases: polymorphic types (interfaces/unions), deeply nested objects

devin-ai-integration bot and others added 3 commits October 15, 2025 18:09
… response type reuse; gradle/maven wiring; tests and fixtures

Co-Authored-By: Arthur Poon <[email protected]>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 2 commits October 15, 2025 23:18
…ponses from default generator IT

Co-Authored-By: Arthur Poon <[email protected]>
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.

1 participant