graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Feature Request: Generate gql tagged operations and reuse external types/enums with manual type generation setup

Open usama-liaqat opened this issue 5 months ago • 0 comments

Is your feature request related to a problem? Please describe.

Currently, when using the client preset in GraphQL Code Generator, it automatically generates:

  • gql tagged documents for operations
  • Fully typed operation hooks (with operation result, variables, etc.)
  • Reused and centralized type definitions (great for large codebases)

However, if we opt not to use the client preset and instead define our type generation manually (for better control or separation of concerns), we lose the ability to:

  1. Auto-generate gql tagged documents.
  2. Reuse external shared GraphQL types/enums/interfaces instead of generating inline types per operation.
  3. Avoid type conflicts when the same GraphQL type is reused across the system.

Describe the solution you'd like

  1. Auto-generate gql function:
    • Even without using client preset, allow a plugin/preset to auto-generate the gql tagged operations from .graphql or .gql documents.
  2. Separate concerns cleanly:
    • Allow generating types/enums/interfaces in a shared file (types.generated.ts)
    • Generate operations.generated.ts that imports and reuses types from types.generated.ts, instead of inlining them or generating duplicates.
  3. Type Reuse for Query/Mutation results:
    • If a query references a User type and it already exists in types.generated.ts, I want the generated query result type to reuse that, or at least deeply pick from that.
    • Avoids issues where I need to update the same type/interface in multiple places if the schema changes.

Describe alternatives you've considered

No response

Any additional important details?

  • For large projects and monorepos, separating types and operations is essential for code clarity and maintainability.
  • Centralized shared types prevent fragmentation and reduce bugs.
  • Manually maintaining type alignment between generated and custom logic is time-consuming and error-prone.

usama-liaqat avatar Jun 11 '25 08:06 usama-liaqat