Quick q… (note: edited to correct my description o...
# apollo-kotlin
c
Quick q… (note: edited to correct my description of the web behaviour) We have web, Android, and iOS clients consuming graphql schemas. On Android and iOS, schemas gets downloaded and checked into the client repos, and the generated code is gitignored. However, our web projects fetch the schema, do codegen, and check the generated code into the repo, and discard the schema. We don’t have consensus on what is the correct approach (or if one is better than the other). Any reason one is better than the other?
w
I don't think I get it, mobile clients check in schema/queries into the repo, so they generate code during the build, so they can gitignore the generated code. Web fetches the schema in the build step and checks in the generated code. So to update the schema I'd run the build and commit the resulting code? And if I want to run e.g. an old commit, I'd run it in some mode that disables fetching the schema?
Fwiw on mobile we do it as you do on mobile too, commit schema and queries and ignore generated code. I find it difficult to understand why someone would do it differently in the first place 🤔
b
As a general rule, if you want reproducible builds, I'd avoid downloading the schema at build time, but instead, manually download it and check it in the repo. As the schema can evolve. About checking in the generated source, it's a bit odd to do that and people usually don't.
So yeah agreed with @wasyl here, I'd go with what the iOS and Android teams do.
c
Sorry I realize I wrote this incorrectly. On web, codegen is not performed as part of build. There is an explicit codegen command which fetches the schema and generates the code. It does not run as part of build, so yes you can switch to an old commit and run the build, it will work as expected because the generated code is checked in.
s
Just giving my perspective here too. Not checking in the schema has turned out to be a real hassle when I’ve had to run some older version of the code since I had to also manually change stuff in the schema to make the whole thing compile again. From that point I understood that checking in the schema is the right approach. If you don’t like the diff noise, you can even look into this https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github to make it not show by default in those PRs
c
I will talk to our web people. I don’t think there is necessarily a reason the generated code is checked in, except that it’s always been done that way on those projects.
Thanks for the feedback