Skip to content

refactor: replace Option wrappers with serde(default) attribute#382

Merged
tusharmath merged 5 commits intotailcallhq:mainfrom
meskill:refactor/config-option-wrappers
Oct 1, 2023
Merged

refactor: replace Option wrappers with serde(default) attribute#382
tusharmath merged 5 commits intotailcallhq:mainfrom
meskill:refactor/config-option-wrappers

Conversation

@meskill
Copy link
Copy Markdown
Contributor

@meskill meskill commented Sep 29, 2023

Summary:

Instead of Option<bool> etc use #[serde(default)] to mark fields as optional with some default value.

These changes simplifies the code and prevents possible bugs when utilizing Option

Issue Reference(s):
Fixes #371

/claim #371

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh to address and fix linting issues.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly (if applicable).
  • I have performed a self-review of my own code.

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 29, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (6a8fce3) 82.44% compared to head (1fab23d) 82.35%.

❗ Current head 1fab23d differs from pull request most recent head 6396689. Consider uploading reports for the commit 6396689 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #382      +/-   ##
==========================================
- Coverage   82.44%   82.35%   -0.09%     
==========================================
  Files          46       46              
  Lines        4142     4104      -38     
==========================================
- Hits         3415     3380      -35     
+ Misses        727      724       -3     
Files Coverage Δ
src/blueprint/from_config.rs 96.20% <100.00%> (+0.34%) ⬆️
src/config/config.rs 81.19% <100.00%> (-0.32%) ⬇️
src/config/from_document.rs 98.06% <100.00%> (-0.12%) ⬇️
src/config/n_plus_one.rs 99.66% <100.00%> (-0.01%) ⬇️
src/config/into_document.rs 88.05% <78.57%> (-0.24%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@meskill
Copy link
Copy Markdown
Contributor Author

meskill commented Sep 29, 2023

I've tried to replace as much properties as possible but changing some fields (like in Http) breaks tests as now deserialization of config to sdl outputs more types that were initially provided. That requires either changing tests itself or how identity is compared

@tusharmath
Copy link
Copy Markdown
Contributor

Identity tests are required because there are use cases where we generate a new config using open API or Adobe other format. Some times we want to merge two config into one. I don't think we should change it.

@meskill
Copy link
Copy Markdown
Contributor Author

meskill commented Sep 30, 2023

Identity tests are required because there are use cases where we generate a new config using open API or Adobe other format. Some times we want to merge two config into one. I don't think we should change it.

Could you please point out to some examples or documentation about this to better understand current usage?

Identity tests should stay I agree, but to be able to replace Option to default we could:

  • leave that pr as is with replaced entries that do not affect actual output (like in Field) while leave other entries as is (that are related to directives)
  • improve identity tests that they are validate that output == input + defaults and not just input == output

@tusharmath
Copy link
Copy Markdown
Contributor

Think about Config as a reduced form of input from the user. The user (a human) can write a Json, Yaml, GraphQL or use a GUI to create an input to tailcall. Let's say the input is of type "I". Now here is what happens next:

  • Convert "I" into a consistent input format which in our case is called as "Config". All inputs should be converted into a "Config".
  • From Config, we convert to Blueprint and then into a GraphQL executor.
  • The reason why we need to have a consistent input format — Config, is that we should be able to convert from one input format to another. So a user could write in .json format, but could allow it to be converted into a .graphql format. Or a user could use a GUI to generate .graphql config, download it and start the server.

I hope this makes sense. Let me know if it doesn't, happy to talk more about the architecture and the reason behind it.

Feel free to connect with us on [discord] if you prefer a more real time collaboration :)

@tusharmath
Copy link
Copy Markdown
Contributor

The identity tests, guarantee that we always generate the most minimal and compact configuration that's possible. This is one of the reasons why we started with the Option wrapping.

@tusharmath
Copy link
Copy Markdown
Contributor

Identity tests are required because there are use cases where we generate a new config using open API or some other format. Some times we want to merge two config into one. I don't think we should change it.

It's not Adobe I meant some

@meskill
Copy link
Copy Markdown
Contributor Author

meskill commented Sep 30, 2023

The identity tests, guarantee that we always generate the most minimal and compact configuration that's possible. This is one of the reasons why we started with the Option wrapping.

In case we want to generate as minimal configuration as possible from Config I have a suggestion to use serde's skip_serializing. In that case fields with that attribute won't appear in the output if they have a default value.

Please, look at my latest commit that shows the example of usage.

One possible side effect of this is that some input settings could disappear from the output if they are equal to the default value

@tusharmath
Copy link
Copy Markdown
Contributor

I think this is going in the right right direction. We have a few pending Option<Vec<_>>.

@meskill meskill force-pushed the refactor/config-option-wrappers branch from c420727 to 1fab23d Compare October 1, 2023 06:22
@meskill
Copy link
Copy Markdown
Contributor Author

meskill commented Oct 1, 2023

I think this is going in the right right direction. We have a few pending Option<Vec<_>>.

Updated other fields that has clear defaults. Please, note the comment why some Option<Vec> wasn't replaced

@tusharmath tusharmath force-pushed the refactor/config-option-wrappers branch from 1fab23d to 6396689 Compare October 1, 2023 08:25
@tusharmath
Copy link
Copy Markdown
Contributor

/tip $50 @meskill

@algora-pbc
Copy link
Copy Markdown

algora-pbc bot commented Oct 1, 2023

🎉🎈 @meskill has been awarded $50! 🎈🎊

@tusharmath tusharmath enabled auto-merge (squash) October 1, 2023 08:26
@tusharmath tusharmath merged commit 3b37d0f into tailcallhq:main Oct 1, 2023
@meskill meskill deleted the refactor/config-option-wrappers branch October 1, 2023 09:34
@github-actions github-actions bot added the type: chore Routine tasks like conversions, reorganization, and maintenance work. label Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🙋 Bounty claim type: chore Routine tasks like conversions, reorganization, and maintenance work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unnecessary Option wrapping in Config.rs

2 participants