Skip to content

Commit

Permalink
[graphql/rpc] easy: allows loading cfg from path (#14244)
Browse files Browse the repository at this point in the history
## Description 

Needed for easier deploys

## Test Plan 

Manual

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
oxade authored Oct 13, 2023
1 parent 53b99fa commit 04caa59
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions crates/sui-graphql-rpc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ pub enum Command {
#[clap(short, long)]
file: Option<PathBuf>,
},
FromConfig {
/// Path to TOML file containing configuration for server.
#[clap(short, long)]
path: PathBuf,
},
StartServer {
/// URL of the RPC server for data fetching
#[clap(short, long)]
Expand Down
6 changes: 5 additions & 1 deletion crates/sui-graphql-rpc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ impl ServerConfig {
serde_yaml::from_str::<Self>(&contents).unwrap()
}

pub fn to_yaml(&self) -> String {
serde_yaml::to_string(&self).unwrap()
}

pub fn to_yaml_file(&self, path: PathBuf) {
let config = serde_yaml::to_string(&self).unwrap();
let config = self.to_yaml();
std::fs::write(path, config).unwrap();
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/sui-graphql-rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap::Parser;
use sui_graphql_rpc::commands::Command;
use sui_graphql_rpc::config::{ConnectionConfig, ServiceConfig};
use sui_graphql_rpc::schema_sdl_export;
use sui_graphql_rpc::server::builder::Server;
use sui_graphql_rpc::server::simple_server::start_example_server;

#[tokio::main]
Expand Down Expand Up @@ -38,6 +39,11 @@ async fn main() {
println!("Starting server...");
start_example_server(conn, service_config).await;
}
Command::FromConfig { path } => {
let server = Server::from_yaml_config(path.to_str().unwrap());
println!("Starting server...");
server.await.run().await;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-graphql-rpc/src/server/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use hyper::server::conn::AddrIncoming as HyperAddrIncoming;
use hyper::Server as HyperServer;
use std::{any::Any, net::SocketAddr, sync::Arc};

pub(crate) struct Server {
pub struct Server {
pub server: HyperServer<HyperAddrIncoming, IntoMakeServiceWithConnectInfo<Router, SocketAddr>>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-graphql-rpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

pub mod simple_server;

mod builder;
pub mod builder;
mod version;

2 comments on commit 04caa59

@vercel
Copy link

@vercel vercel bot commented on 04caa59 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mysten-ui – ./apps/ui

mysten-ui-mysten-labs.vercel.app
mysten-ui-git-main-mysten-labs.vercel.app
mysten-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 04caa59 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.