-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onlyOperationTypes to include only used enum types #10232
Comments
Hi @ThePlenkov , you mentioned in #10233 you can use a tool to remove unused export? Could you do that for unused enums? |
that's correct! I found it later, after this issue created. But it appeared later that i don't even need knip. Generating enums as union types + noExport + bundilng your project will do a tree shaking and only generate required types. However in this case we need to extract types again from the only exported type getSdk, so it's not that much convenient. Additionally, if we want to use real enums, then even not being exported - it will be still generated in the bundle as a variable ( at least my rollup configuration do this ) So it's not in d.ts file but still make bundle size huge. ( 300KB -> 1KB ) So which logic I would apply porgrammatically:
In this case we'll just give the perfect ts file to the bundler. I tried this concept manually - it works, but of course doesn't fit for automated development |
so knip.dev only removes exports for enums, but doesn't remove enums themselves. It doesn't support unused variables or type properties yet. Otherwise it would be very helpful here indeed |
Actually today I already found another principally different way. Instead of typescript manipulating - I thought - what if we just manipulate only graphql schema. So I found other tools from the guild: filtering and cleanup transformations. This code seems to be working exactly how I want:
So it filters out unnecessary query types and this triggers pruning first types, then enums Exactly what I want - feeding this schema to codegen would solve the issue. Now new problem is - i'd like still to use codegen. I see schema is required to be URL or path, so I cannot provide GraphQLSchema "as is" Do you know may be some recommeded ways to transform schema on the fly? @eddeee888 Thanks! |
Awesome! Glad you found the tools to do it! To use the pruned schema, maybe you could:
|
Actually I was able to debug and file that I was also disappointed to find out - that this magic "Delete all unused declarations" button in VS Code - is a very unique IDE feature and do not have some reusable library to repeat this.. Still searching for a right way to prune ts document. As what I mentioned - unfortunately noExport comes with a side effect that no types are exported at all |
I see! |
Is your feature request related to a problem? Please describe.
So I want to build an SDK for Gitlab graphql API. I only have few queries - for that purpose I've created them as separate graphql documents and I want to generate getSDK with few methods.
By default my SDK contains 50K lines, with
onlyOperationTypes
it gets reduced to 13K, however, if I check generated sdk.ts i have many enums which are not in use in any of types therefore it's just meaningless to generated them.Describe the solution you'd like
As a proposal we may introduce a feature like
dedupeEnums
which should remove not used enums, it may be default to true if onlyOperationTypes is true.What do you think about this proposal?
Describe alternatives you've considered
No response
Any additional important details?
No response
The text was updated successfully, but these errors were encountered: