From e1125a5f14c2e1ecc6383820486ad8d09234f41e Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Wed, 19 Jun 2024 22:34:01 +0100 Subject: [PATCH] [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 ``` --- crates/sui-graphql-rpc/src/commands.rs | 7 +++++++ crates/sui-graphql-rpc/src/main.rs | 13 +++++++++++++ .../sui-graphql-rpc/src/server/graphiql_server.rs | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/sui-graphql-rpc/src/commands.rs b/crates/sui-graphql-rpc/src/commands.rs index bda0c2f561fab2..a5da268afcf3dc 100644 --- a/crates/sui-graphql-rpc/src/commands.rs +++ b/crates/sui-graphql-rpc/src/commands.rs @@ -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 + }, + StartServer { /// The title to display at the top of the page #[clap(short, long)] diff --git a/crates/sui-graphql-rpc/src/main.rs b/crates/sui-graphql-rpc/src/main.rs index 349ef0f0f74a4a..cedc55b39e72ac 100644 --- a/crates/sui-graphql-rpc/src/main.rs +++ b/crates/sui-graphql-rpc/src/main.rs @@ -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, diff --git a/crates/sui-graphql-rpc/src/server/graphiql_server.rs b/crates/sui-graphql-rpc/src/server/graphiql_server.rs index d5c2f329ecf7f1..7a809c01d85be7 100644 --- a/crates/sui-graphql-rpc/src/server/graphiql_server.rs +++ b/crates/sui-graphql-rpc/src/server/graphiql_server.rs @@ -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?,