MystenLabs / sui

Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
https://sui.io
Apache License 2.0
5.84k stars 11.06k forks source link

[pick #18347][GraphQL] Fix bug where config types "zero out" fields not in TOML #18381

Closed amnn closed 2 days ago

amnn commented 4 days ago

Description

When a field is labeled with #[serde(default)] it means that if that field is not present, it is populated using the Default impl for the field's type:

#[derive(Serialize, Deserialize, Clone, Debug)]
struct Foo {
    #[serde(default)]
    bar: Bar,
}

Foo { bar: Bar::default() }

This is not the behaviour we want, however. We want fields that have not been supplied to be populated with their value from the Default impl of the type they are part of:

Foo { bar: Foo::default().bar }

Implementing this manually requires a lot of boilerplate -- each field needs to have an associated function that returns its default value:

#[derive(Serialize, Deserialize, Clone, Debug)]
struct Foo {
    #[serde(default = "Foo::__default_bar")]
    bar: Bar,
}

So this PR introduces an attribute proc macro to perform this transformation:

#[GraphQLConfig]
struct Foo {
    bar: Bar,
}

It also performs some other related clean-ups:

Test plan

Added a test for reading a ServiceConfig from an incomplete/partial TOML:

sui-graphql-rpc$ cargo nextest run -- read_partial_in_service_config

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

vercel[bot] commented 4 days ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2024 11:08am
3 Ignored Deployments | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **multisig-toolkit** | ⬜️ Ignored ([Inspect](https://vercel.com/mysten-labs/multisig-toolkit/4kkWqETUKx3BUkEuWj3syEgAzSHp)) | [Visit Preview](https://multisig-toolkit-git-amnn-pick-18347-20241-mysten-labs.vercel.app) | | Jun 26, 2024 11:08am | | **sui-kiosk** | ⬜️ Ignored ([Inspect](https://vercel.com/mysten-labs/sui-kiosk/F16rBw3LdcrboPjSJQfH88Q6D8gs)) | [Visit Preview](https://sui-kiosk-git-amnn-pick-18347-20241-mysten-labs.vercel.app) | | Jun 26, 2024 11:08am | | **sui-typescript-docs** | ⬜️ Ignored ([Inspect](https://vercel.com/mysten-labs/sui-typescript-docs/FwJfrxnLoC2a2kYHqRbyJoPHZZHW)) | [Visit Preview](https://sui-typescript-docs-git-amnn-pick-18347-20241-mysten-labs.vercel.app) | | Jun 26, 2024 11:08am |