dotansimha / dotansimha/graphql-code-generator

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

Open
#10,369 2 comments 0 reactions 1 assignee Claimed by @eddeee888 View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### 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.
3. Reuse external shared GraphQL types/enums/interfaces instead of generating inline types per operation.
5. 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.