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

Interfaces produce huge union types that become unmaintainable

Open rcoopr opened this issue 3 years ago • 1 comments

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/issues/3863

Additional context Sample output here:

type GetJudgeTournamentEventQuery = { event?: Maybe<{ id: string, activeClassId?: Maybe<string>, activeEvent?: Maybe<{ id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> } | { id: string, name?: Maybe<string> }>, children?: Maybe<Array<Maybe<{ id: string, name?: Maybe<string>, children?: Maybe<Array<Maybe<(
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_BasicCompetition_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_BasicHeat_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_BasicRound_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_DriftBattleHeat_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_DriftRound_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_DriftTandemTournament_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_LeadClimbingRound_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_League_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_Session_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_TimedRuns_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_Tournament_Fragment
      ) | (
        { id: string, name?: Maybe<string> }
        & JudgeTournamentHeatDetail_TournamentRound_Fragment
      )>>> } | ...

rcoopr avatar Jan 14 '22 10:01 rcoopr

Try mergeFragmentTypes: true

joshjg avatar Aug 12 '22 13:08 joshjg