Skip to content
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

CLI: Add checksum calculation to avoid unecessary processing when generating code #20

Merged
merged 2 commits into from
Dec 5, 2022

Conversation

jarlef
Copy link
Contributor

@jarlef jarlef commented Dec 4, 2022

Append checksum on the generated source code based on the input schema file + generator options (namespace + client name). This checksum is initial read on subsequent generation. If the input graphql schema and generator options hasn't changed, then the process can be aborted since the source code is up to date.

Purpose

I think the ZeroQL is a good framework to use as typed client for our backend tests. We output the schema file from our backend and then our xunit test project compiles the ZeroQL client as part of pre build step. Since ZeroQL.CLI tool is now baked into our build pipeline, we want optimise the performance. The best approach is to skip source generation when the generated code is up to date with the existing schema.

Benchmarks

Method Mean Error StdDev
GenerateWithoutChecksumOptimization 7,640.75 us 151.703 us 141.903 us
GenerateWithChecksumOptimization 83.76 us 1.624 us 1.356 us

CLI

Added new option "Force" to skip checksum check and output generate source code (if this is somehow needed)

@byme8
Copy link
Owner

byme8 commented Dec 5, 2022

Can you add a test for this use case? A nice place would be the CLITests. It can check that if you execute commands twice, the second time should output The source code is up-to-date with graphql schema. Skipping code generation.

@byme8
Copy link
Owner

byme8 commented Dec 5, 2022

Overall nice addition! Thanks!

@jarlef
Copy link
Contributor Author

jarlef commented Dec 5, 2022

I have updated the CLITests that checks both the outputted message but also checks that the write timestamp is also correct on the physical source code file. I also decided to add the ZeroQL.CLI version number into the checksum since a new version might produce different source code than earlier versions

@byme8 byme8 merged commit 6b00048 into byme8:main Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants