Skip to content

Conversation

@devin-ai-integration
Copy link

📝 Description

This PR implements the first step of a feature to allow shared response types in the GraphQL Kotlin client generator. Currently, the system generates duplicate classes for the same GraphQL type when it appears in different operations. This change adds the infrastructure to track and identify response types that are shared across multiple operations.

Key Changes:

  • Added tracking infrastructure: New responseClassToTypeSpecs map in GraphQLClientGeneratorContext to track response types, similar to existing enum and input type tracking
  • Implemented shared type detection: New detectSharedResponseTypes() method that analyzes all operation contexts to identify types used across multiple operations
  • Extended shared types system: Response types are now included in the sharedTypes collection alongside enums, input types, and scalar converters
  • Refactored generation flow: Updated the main generate() method to collect contexts from all operations before processing shared types

Important Notes:

  • This is explicitly the "first step" - actual deduplication logic is not implemented yet
  • The infrastructure identifies shared types but doesn't yet prevent duplicate class generation
  • Future work will involve implementing the logic to actually use shared types instead of generating per-operation duplicates

Testing:

  • All existing tests pass (63 tests, 0 failures)
  • ktlint and detekt checks pass with 0 code smells

Key Areas for Review:

  1. Shared type detection logic: Verify the detectSharedResponseTypes() method correctly identifies types used across multiple operations
  2. Performance implications: The new detection processes all contexts and type specs - assess impact on large codebases
  3. Integration patterns: Ensure the response type tracking follows the same patterns as existing enum/input type sharing
  4. Edge cases: Consider polymorphic types, complex selection sets, and other GraphQL type scenarios
  5. Refactoring safety: Verify the generateWithContext() refactoring maintains existing behavior

🔗 Related Issues

This implements the first step toward resolving duplicate class generation for GraphQL response types across operations, as requested by @akkp-windsurf.

Link to Devin run: https://app.devin.ai/sessions/355a9ae4e762480a804152127e6e1f92
Requested by: Arthur Poon (@akkp-windsurf)

- Add responseClassToTypeSpecs map to GraphQLClientGeneratorContext
- Implement detectSharedResponseTypes method to identify types used across multiple operations
- Extend sharedTypes collection to include response types
- First step toward sharing response types across operations to avoid duplicate class generation

This implementation adds the infrastructure for tracking shared response types but doesn't yet implement the logic to actually deduplicate them across operations. Future steps will involve:
- Logic to determine when response types can be shared (same GraphQL type + compatible selection sets)
- Updating the file generation logic to use shared response types instead of per-operation types
- Handling edge cases around polymorphic types and selection set compatibility

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

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