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

Improve `onlyOperationTypes` implementation

Open dotansimha opened this issue 5 years ago • 10 comments

Related: https://github.com/dotansimha/graphql-code-generator/issues/4373#issuecomment-658326469

dotansimha avatar Aug 12 '20 07:08 dotansimha

@dotansimha copying my comment from that thread in here. I'm not sure if this ticket is meant to track improvements related to my comment, so I wanted to flag:


@dotansimha to pile on to the use case here, for large federated graphs, my total file size generated is nearing 2MB. The number of exports and types seems like it puts an unnecessary strain on the TS compiler and IDE.

This combination:

  preResolveTypes: true
  onlyOperationTypes: true

is useful and has significantly reduced my file size, but it's still generating all enum and input types in the graph, rather than just the ones I'm using in my queries.


dannycochran avatar Sep 30 '20 18:09 dannycochran

Copying my issue use-case: We are connecting to an GraphQL API which has a lot of endpoints so the generated types declaration file is huge (10k lines long). It would be great if it would only create types for used types in the .graphql files and additionally through an option which I also want to force adding.

muuvmuuv avatar Oct 20 '20 07:10 muuvmuuv

Same issue I use postgraphile and codgen to generate an api for our database, but the file types are huge, massively slows down IDE.

RoryKelly avatar Nov 24 '20 22:11 RoryKelly

Is there any workaround for this siutation? Have massive file filled with mostly unused types. Got it better with

preResolveTypes: true
onlyOperationTypes: true

but still have a lot of unused stuff

cipriancaba avatar Apr 04 '21 08:04 cipriancaba

This is a big setback for this library & resulting us in not using this generator.

Moniv9 avatar Sep 06 '21 09:09 Moniv9

@Moniv9 Feel free to help us since it is an opensource project :) We'd love to accept a PR that improves this feature.

ardatan avatar Sep 07 '21 10:09 ardatan

I'd like to bump this issue. We currently have a fastly growing monorepo setup where each package has its own codegen that uses the following config to generate types and hooks for each package.

plugins:
   - typescript
   - typescript-operations
   - typescript-react-apollo
config:
      preResolveTypes: true
      onlyOperationTypes: true

The extra unused enums that get generated for each package end up getting bundled multiple times which has significantly increased our bundle size.

Edit: Using enumsAsTypes: true solves for the bloated build but requires significant code changes.

offirgolan avatar Nov 19 '21 17:11 offirgolan

Hi!

An update on this issue has been posted here:

https://github.com/dotansimha/graphql-code-generator/pull/7150#issuecomment-1023085941

We have a project planned for later this year of refactoring the way plugins operate, with better architecture and different usage of the visitor pattern. This refactoring will be started as a pilot on a new plugin that shares many goals with this PR, a new plugin optimized for client-side usage, only keeping the types used in the defined operations.

charlypoly avatar Jan 27 '22 10:01 charlypoly

@charlypoly any updates on the plugin mentioned above?

warrenzhang23 avatar Nov 01 '23 18:11 warrenzhang23

@warrenzhang23

I ended up publishing my rejected plugin up to npm as a drop in replacement for the typescript plugin as we couldn't wait for a "later this year" back in Jan 2022. That might be of use to you? My company has been using it for quite a while in a large nx repository without any issues.

https://www.npmjs.com/package/graphql-codegen-typescript-operation-types

Stonepaw avatar Dec 21 '23 17:12 Stonepaw