#![deny(missing_docs)]
#[path = "commands/mod.rs"]
mod commands;
use crate::commands::OneshotArgs;
use crate::commands::ProxyArgs;
use crate::commands::SchemaArgs;
use crate::commands::exec_oneshot;
use crate::commands::exec_proxy;
use crate::commands::exec_schema;
use clap::Parser;
use clap::Subcommand;
use mockql_core::SchemaFilterError;
use mockql_core::SchemaLoadError;
use mockql_core::ServiceError;
use std::process::ExitCode;
use thiserror::Error;
#[derive(Debug, Parser)]
#[command(name = "mockql", about = "AI Generated GraphQL response mocking via @mock")]
struct MockQLCli {
#[command(subcommand)]
command: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
#[command(about = "Execute a single mock GraphQL request and print the result to stdout")]
Oneshot(OneshotArgs),
#[command(about = "Start a HTTP proxy server that mocks GraphQL responses")]
Proxy(ProxyArgs),
#[command(about = "Print a GraphQL schema decorated with the mock directive")]
Schema(SchemaArgs),
}
#[derive(Debug, Error)]
pub(crate) enum CliError {
#[error("failed to read file: {0}")]
Io(#[from] std::io::Error),
#[error("failed to parse JSON: {0}")]
Json(#[from] serde_json::Error),
#[error("{0}")]
Message(String),
#[error(transparent)]
Schema(#[from] SchemaLoadError),
#[error(transparent)]
SchemaFilter(#[from] SchemaFilterError),
#[error("failed to build HTTP client: {0}")]
ClientInit(String),
#[error(transparent)]
Service(#[from] ServiceError),
}
#[tokio::main]
async fn main() -> ExitCode {
let result = match MockQLCli::parse().command {
Commands::Oneshot(args) => exec_oneshot(args).await,
Commands::Proxy(args) => exec_proxy(args).await,
Commands::Schema(args) => exec_schema(args).await,
};
match result {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
eprintln!("{error}");
ExitCode::FAILURE
}
}
}