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

indexer-alt: generalize GraphQLConfig #20460

Merged
merged 3 commits into from
Nov 29, 2024
Merged

Conversation

amnn
Copy link
Member

@amnn amnn commented Nov 28, 2024

Description

Take the GraphQLConfig procedural macro used by GraphQL and generalize it for use in other crates, as DefaultConfig. This macro simplifies defining a configuration to be read from a file, using serde's Serialze/Deserialize, and automatically using the type's Default to supply the default values while deserializing as well.

As part of generalizing, we dropped support for some features that don't work well in the more general setting:

  • We no longer derive a number of other traits (like Clone, Eq, etc) -- these can be added manually if needed.
  • We no longer force field names to be rename_all = "kebab-case", because for the Indexer's config, we will want some of them to be renamed as "snake_case". A check was added to see whether a rename_all attribute has been supplied, and in that case, the macro does not add its own.

Test plan

Build and test existing uses of the crate:

sui$ cargo nextest run -p sui-graphql-rpc
sui$ cargo nextest run -p sui-graphql-e2e-tests
sui$ cargo nextest run -p sui-mvr-graphql-rpc

Stack


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.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

amnn added 3 commits November 28, 2024 11:24
## Description

`GraphQLConfig` is a derive macro for deriving `Serialize`,
`Deserialize`, and `Debug`, and introducing `#[serde(default = ...)]`
annotations that rely on the fields of the type's `Default`
implementation.

This allows config types to rely on their `Default` implementation as a
single source of truth for default values, and is used through-out
`sui-graphql-rpc` to define its config types.

This change generalizes it (renames it) so it can be used in the indexer
as well.

## Test plan

Build and test `sui-graphql-rpc`, `sui-mvr-graphql-rpc`:

```
sui$ cargo nextest run -p sui-graphql-rpc
sui$ cargo nextest run -p sui-graphql-e2e-tests
sui$ cargo nextest run -p sui-mvr-graphql-rpc
```

This is a behaviour preserving change for the moment.
## Description

`DefaultConfig` previously automatically added derives for `Serialize`,
`Deserialize`, and `Clone`, `Eq` and `PartialEq`, which was convenient
for its use in `sui-graphql-rpc`, but it does not generalize well,
because:

- Currently, it requires that the traits are in scope, which somewhat
  defeats the point of not having to explicitly derive them, in the case
  of `Serialize`/`Deserialize`.
- The logic to detect when a derive is already applied is fragile,
  because it works by name (so it wouldn't play nicely with
  fully-qualified or aliased derives).

This change removes that support in favour of a simpler approach:

- `DefaultConfig` adds derives for `serde::Serialize` and
  `serde::Deserialize`, using fully-qualified names.
- Other derives need to be added explicitly.
- The logic to only add a derive if it hasn't already been added has
  been removed.

## Test plan

CI for existing use cases.
## Description

Add support to `sui-default-config` to change the naming scheme of its
fields (previously always used kebab-case). This allows pipelines to
retain the names they were given in source code (which use underscores).

## Test plan

Will be used and tested in a future PR.
@amnn amnn self-assigned this Nov 28, 2024
Copy link

vercel bot commented Nov 28, 2024

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Nov 28, 2024 1:29pm
sui-kiosk ⬜️ Ignored (Inspect) Nov 28, 2024 1:29pm
sui-typescript-docs ⬜️ Ignored (Inspect) Nov 28, 2024 1:29pm

@amnn amnn merged commit ad67683 into amnn/idx-cfg-ms Nov 29, 2024
49 checks passed
@amnn amnn deleted the amnn/idx-cfg-default branch November 29, 2024 17:11
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env November 29, 2024 17:12 — with GitHub Actions Inactive
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