dotansimha / dotansimha/graphql-code-generator

Interfaces produce huge union types that become unmaintainable

Open
#7,366 1 comment 0 reactions 0 assignees View on GitHub
core
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.**
I have inherited a codebase that has a large number of operations, and many many interfaces. Using the `typescript-operations` plugin with no config produces a 148MB file with 4.4million lines. With preResolveTypes it becomes 56MB and 35k lines. One particular query type is 5,000 lines alone. I don't know if this is expected but it seems to make working with interfaces very difficult when there are many types extending the same interface

**Describe the solution you'd like**
Having some way to handle these with a base interface type or creating a union at each field instead of the entire object. See https://github.com/dotansimha/graphql-code-generator/pull/6826 for what I believe is a related PR

**Describe alternatives you've considered**
I have tried the nea-operation-file preset however many of my gql operations rely on introspection types such as `__type`, which has resulted in errors with that preset. See https://github.com/dotansimha/graphql-code-generator-community/issues/110

**Additional context**
Sample output here:
```ts
type GetJudgeTournamentEventQuery = { event?: Maybe<{ id: string, activeClassId?: Maybe, activeEvent?: Maybe<{ id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe } | { id: string, name?: Maybe }>, children?: Maybe, children?: Maybe }
& JudgeTournamentHeatDetail_BasicCompetition_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_BasicHeat_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_BasicRound_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_DriftBattleHeat_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_DriftRound_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_DriftTandemTournament_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_LeadClimbingRound_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_League_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_Session_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_TimedRuns_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_Tournament_Fragment
) | (
{ id: string, name?: Maybe }
& JudgeTournamentHeatDetail_TournamentRound_Fragment
)>>> } | ...
```

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.