cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety
https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/
MIT License
204 stars 25 forks source link

[Case study] Type-checking in CI #85

Closed cometkim closed 2 years ago

jazeved0 commented 4 years ago

Hey, just wanted to leave some feedback on CI using gatsby-plugin-typegen from the perspective of the project I'm working on. In our repo, we exclude the generated types from version control, and instead let them get generated upon the first run. Part of the reasoning for this is that we use gatsby-source-graphql with the GitHub API, which causes the generated schema to (expectedly) include the entire GitHub API GraphQL schema. Because of this, we have to build the site before running ESLint or tsc during CI. In my experience, running gatsby develop and gatsby build causes different types to be generated, so builds on CI will fail when they run gatsby build before tsc to typecheck.

A workaround I made for this is to have a script run gatsby develop on CI and kill the process once it successfully finishes (otherwise it would keep running to serve the dev server). This allows us to run this before typechecking/linting and correctly mirrors the same types that are generated while developing.

In the future, it would be useful if gatsby develop and gatsby build didn't produce different types, though I'm sure there are technical reasons that this is the case. Alternatively, it would also be convenient to have some way to run the code generation for the schema in a way that didn't involve the entire site build, so that it would be faster in CI. However, I know that the schema generation is tied to the internal schema built by Gatsby at runtime, so I'm not sure how possible this is (perhaps the build could be forcibly stopped at some point in the Gatsby build lifecycle after the codegen runs and before the bundles are made/rendered).

cometkim commented 4 years ago

Thank you @jazevedo620 for leaving feedback here.

It sounds pretty bad for me that gatsby develop and gatsby build produce different schema/types. Can you share your site configuration?

Maybe I can add a flag to exit process after all tasks are done once. Or I guess to add fork-ts-checker webpack plugin could integrate type-checking to gatsby build seamlessly.

cometkim commented 2 years ago

The schema and documents outputs are stable since v3.

I will open another issue for further enhancement on CI env