Improve `onlyOperationTypes` implementation
Related: https://github.com/dotansimha/graphql-code-generator/issues/4373#issuecomment-658326469
@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.
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.
Same issue I use postgraphile and codgen to generate an api for our database, but the file types are huge, massively slows down IDE.
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
This is a big setback for this library & resulting us in not using this generator.
@Moniv9 Feel free to help us since it is an opensource project :) We'd love to accept a PR that improves this feature.
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.
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 any updates on the plugin mentioned above?
@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