-
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
[typescript] Add the ability to only output types used by the queries #6959
Comments
At the moment, you can use |
Seems to be on the roadmap:
|
For what it's worth, I've managed to implement this functionality as a post-generation cleanup script. I can't take the time to create an MR but I will share my code here, as documented as possible. I welcome anyone to adapt into into a functional MR for this library :) Assumptions
Overall Approach
Code
|
Hey there 👋
First of all, thanks so much for this amazing library. I've really enjoyed how flexible and configurable this tool is.
I'd love to add the ability to generate only the TypeScript types used by the schema. Currently the entire GraphQL schema + query/mutation types (with
typescript-operations
) are generated and saved to the file. This works great for small to medium-size GraphQL APIs, but gets overwhelming for large GraphQL APIs.I'm working with a very large GraphQL API to generate types for my UI. The UI I'm building uses a small fraction of the GraphQL schema, yet everything in the GraphQL schema is included in my types file. To give you a hard number, our types file has 132,000+ lines of code after codegen.
Because that file is so big, it has a heavy performance impact on a few of our tools such as prettier. We have some tooling in place to automatically apply prettier to files before a commit and we notice that this file eats up a huge chunk of time. Because we also lint our commits, there are times when a minor commit message error can result in a > 10s feedback cycle due to it trying to run prettier on the file before linting the commit message.
As a workaround, we've considered adding this file to something like a
.prettierignore
(and equivalent for other tools), but we really appreciate the prettified code because its much easier to read in diffs for PRs and such. Ideally we'd be able to leverage everything we have right now, but with a much more scaled down file to do so. This would also make it easy for someone to scan that file and understand what is actually used in our UI. As a human reading that file, that file is too big for anyone to fully grasp anything in there.I'd love for this to be considered as a new configuration option that can be enabled. Thanks!
The text was updated successfully, but these errors were encountered: