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

[GraphQL] generate-config sub-command #18336

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[GraphQL] generate-config sub-command
## Description

Add a command for generating a `config.toml` file for the GraphQL
service with all its parameters set to their default values.

## Test plan

```
cargo run --bin sui-graphql-rpc -- generate-config /tmp/config.toml
```
  • Loading branch information
amnn committed Aug 19, 2024
commit 8ac587463a60ca9df5525eafdf2c038fb1c779f3
7 changes: 7 additions & 0 deletions crates/sui-graphql-rpc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ use std::path::PathBuf;
version
)]
pub enum Command {
/// Output a TOML config (suitable for passing into the --config parameter of the start-server
/// command) with all values set to their defaults.
GenerateConfig {
/// Optional path to a file to output to. Prints to stdout if none is provided.
output: Option<PathBuf>,
},

StartServer {
/// The title to display at the top of the page
#[clap(short, long)]
Expand Down
13 changes: 13 additions & 0 deletions crates/sui-graphql-rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ static VERSION: Version = Version {
async fn main() {
let cmd: Command = Command::parse();
match cmd {
Command::GenerateConfig { output } => {
let config = ServiceConfig::default();
let toml = toml::to_string_pretty(&config).expect("Failed to serialize configuration");

if let Some(path) = output {
fs::write(&path, toml).unwrap_or_else(|e| {
panic!("Failed to write configuration to {}: {e}", path.display())
});
} else {
println!("{}", toml);
}
}

Command::StartServer {
ide_title,
db_url,
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-graphql-rpc/src/server/graphiql_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn start_graphiql_server(
version: &Version,
cancellation_token: CancellationToken,
) -> Result<(), Error> {
info!("Starting server with config: {:?}", server_config);
info!("Starting server with config: {:#?}", server_config);
info!("Server version: {}", version);
start_graphiql_server_impl(
ServerBuilder::from_config(server_config, version, cancellation_token).await?,
Expand Down
Loading