Do people check their generated files into Git? #4253
-
Seems like most of the internet says "don't check generated files into version control". Ostensibly to avoid having the "canonical" code (e.g. GraphQL schema) get out of sync with the generated artefacts (whatever gets produced by graphql-code-generator). But if I don't check in those files, then checking out a new branch will leave the generated files from the old branch in my file system. Unless I'm extremely disciplined about re-running codegen after switching branches, the code may break in unexpected ways. Seems like a catch-22. I can't find any best practice on this. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Hi @vriad ! Personally, I prefer not to put generated files under source control. It bloats the repository and increase the size. It also causes merge conflicts in a lot of cases. I usually create |
Beta Was this translation helpful? Give feedback.
-
Ah great stuff! The |
Beta Was this translation helpful? Give feedback.
-
@dotansimha @dannycochran @jamesonhill @colinhacks We are checking in generated files, but do not import from them. Some types generated are completely wrong, and there is a lot of inlined styles generated. Also generated code contains a lot of You should not edit generated files, and I would not recommend you to import from generated files too for reasons described above. I'm checking generated files into the repo, so I can see the diff, and improve edited version accordingly. Yes it is more tedious work, but tools are not perfect yet. I've created a discussion #6741 about some incorrect types generated from schema. |
Beta Was this translation helpful? Give feedback.
-
To me it seems like types (whether they are auto-generated or manually written) are directly coupled to the correct building of the codebase so they should be checked in. If you don't check them in, then you open up the possibility of two separate developers having checking out the same commit and getting two different results when they build. @dotansimha says that he does't check-in types, but it seems like he can get away with this only because:
If you are working in a codebase that doesn't have those three properties then I believe you will have problems that @dannycochran mentions about reproducible builds and commits. |
Beta Was this translation helpful? Give feedback.
Hi @vriad !
Personally, I prefer not to put generated files under source control. It bloats the repository and increase the size. It also causes merge conflicts in a lot of cases.
When possible (for example: your schema is available without running the server), I prefer to run Codegen as part of the CI and build system.
I usually create
pre
script (inpackage.json
) for mystart
andbuild
commands, so if you switch branch, it will run codegen again right before running the actual project. This way you avoid the need to run it manually or remember to run it after changing branches.