apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.87k stars 717 forks source link

Avoid File Overwriting for Unchanged Files #3364

Open reejosamuel opened 5 months ago

reejosamuel commented 5 months ago

Use case

Prevent the overwriting of files during code generation if they have not changed. This is crucial for CI tooling relying on file modification dates for tasks like cache busting and triggering code generation using tools like Sourcery.

Describe the solution you'd like

Introduce a configuration option to control overwriting unchanged files, or by default, prevent such overwriting.

calvincestari commented 5 months ago

Hi @reejosamuel, thanks for the feature suggestion.

I think to make this work we'd have to introduce a checksum of the file body that is written into generated files as a header comment. Currently the overwrite logic is very simplistic and comes down to whether the generated file is one that we allow user edits, such as the schema configuration and custom scalars. If yes then leave the file alone, if no then overwrite it. There is no tracking of generated file diffs at the moment.