diff --git a/.changesets/feat_feature_configvalidatesubcommand.md b/.changesets/feat_feature_configvalidatesubcommand.md new file mode 100644 index 0000000000..4643ca023c --- /dev/null +++ b/.changesets/feat_feature_configvalidatesubcommand.md @@ -0,0 +1,9 @@ +### Add router config validate subcommand ([PR #6131](https://github.com/apollographql/router/pull/6131)) + +Added new `router config validate` subcommand to allow validation of a Router config file without fully starting up the Router. + +``` +./router config validate +``` + +By [@andrewmcgivery](https://github.com/andrewmcgivery) in https://github.com/apollographql/router/pull/6131 diff --git a/apollo-router/src/configuration/mod.rs b/apollo-router/src/configuration/mod.rs index d143f1bd89..f45130a916 100644 --- a/apollo-router/src/configuration/mod.rs +++ b/apollo-router/src/configuration/mod.rs @@ -40,9 +40,10 @@ use self::expansion::Expansion; pub(crate) use self::experimental::Discussed; pub(crate) use self::schema::generate_config_schema; pub(crate) use self::schema::generate_upgrade; +pub(crate) use self::schema::validate_yaml_configuration; +pub(crate) use self::schema::Mode; use self::subgraph::SubgraphConfiguration; use crate::cache::DEFAULT_CACHE_CAPACITY; -use crate::configuration::schema::Mode; use crate::graphql; use crate::notification::Notify; use crate::plugin::plugins; diff --git a/apollo-router/src/configuration/schema.rs b/apollo-router/src/configuration/schema.rs index 4d05b786ef..f474002a67 100644 --- a/apollo-router/src/configuration/schema.rs +++ b/apollo-router/src/configuration/schema.rs @@ -79,9 +79,6 @@ pub(crate) fn generate_config_schema() -> RootSchema { #[derive(Eq, PartialEq)] pub(crate) enum Mode { Upgrade, - - // This is used only in testing to ensure that we don't allow old config in our tests. - #[cfg(test)] NoUpgrade, } diff --git a/apollo-router/src/executable.rs b/apollo-router/src/executable.rs index c246096340..c723f25091 100644 --- a/apollo-router/src/executable.rs +++ b/apollo-router/src/executable.rs @@ -25,9 +25,12 @@ use regex::Regex; use url::ParseError; use url::Url; +use crate::configuration::expansion::Expansion; use crate::configuration::generate_config_schema; use crate::configuration::generate_upgrade; +use crate::configuration::validate_yaml_configuration; use crate::configuration::Discussed; +use crate::configuration::Mode; use crate::metrics::meter_provider; use crate::plugin::plugins; use crate::plugins::telemetry::reload::init_telemetry; @@ -142,6 +145,14 @@ enum ConfigSubcommand { #[clap(action = ArgAction::SetTrue, long)] diff: bool, }, + + /// Validate existing Router configuration file + Validate { + /// The location of the config to validate. + #[clap(value_parser, env = "APOLLO_ROUTER_CONFIG_PATH")] + config_path: PathBuf, + }, + /// List all the available experimental configurations with related GitHub discussion Experimental, /// List all the available preview configurations with related GitHub discussion @@ -432,6 +443,21 @@ impl Executable { println!("{}", serde_json::to_string_pretty(&schema)?); Ok(()) } + Some(Commands::Config(ConfigSubcommandArgs { + command: ConfigSubcommand::Validate { config_path }, + })) => { + let config_string = std::fs::read_to_string(config_path)?; + validate_yaml_configuration( + &config_string, + Expansion::default()?, + Mode::NoUpgrade, + )? + .validate()?; + + println!("Configuration at path {:?} is valid!", config_path); + + Ok(()) + } Some(Commands::Config(ConfigSubcommandArgs { command: ConfigSubcommand::Upgrade { config_path, diff }, })) => { diff --git a/docs/source/reference/router/configuration.mdx b/docs/source/reference/router/configuration.mdx index 50d27a7104..149cf59225 100644 --- a/docs/source/reference/router/configuration.mdx +++ b/docs/source/reference/router/configuration.mdx @@ -347,6 +347,7 @@ GraphOS Router and Apollo Router Core provide a set of subcommands for interacti ``` ./router config schema ./router config upgrade +./router config validate ``` @@ -389,6 +390,21 @@ For details, see [Upgrading your router configuration](#upgrading-your-router-co + + + + +
+ +##### `validate` + + + +Takes a config file and validates it against the router's full supported configuration format. + +Note: This is a static validation that checks if it is syntactically correct using the JSON schema. The router does additional logical checks on startup against the config that this command does not capture. + +