Skip to content

Commit 9621158

Browse files
authored
feat: add --printschema (#5)
2 parents cd6203a + ab05019 commit 9621158

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::path::PathBuf;
1010

1111
use anyhow::{Result, bail};
1212
use argh::FromArgs;
13+
use async_graphql::Schema;
1314

1415
#[cfg(unix)]
1516
use libc::geteuid;
@@ -166,6 +167,10 @@ struct Cli {
166167
/// show version information
167168
#[argh(switch)]
168169
version: bool,
170+
171+
/// print GraphQL schema to stdout
172+
#[argh(switch)]
173+
printschema: bool,
169174
}
170175

171176
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
@@ -185,13 +190,26 @@ async fn main() -> Result<()> {
185190
endpoint,
186191
query,
187192
version,
193+
printschema,
188194
} = argh::from_env();
189195

190196
if version {
191197
println!("riverql {}", env!("CARGO_PKG_VERSION"));
192198
return Ok(());
193199
}
194200

201+
if printschema {
202+
let schema: Schema<gql::QueryRoot, async_graphql::EmptyMutation, gql::SubscriptionRoot> =
203+
Schema::build(
204+
gql::QueryRoot,
205+
async_graphql::EmptyMutation,
206+
gql::SubscriptionRoot,
207+
)
208+
.finish();
209+
println!("{}", schema.sdl());
210+
return Ok(());
211+
}
212+
195213
if server {
196214
if endpoint.is_some() || query.is_some() {
197215
bail!("--server does not take endpoint or query arguments");

0 commit comments

Comments
 (0)