From f80e3d69b93caddb79b177a355c5745f76c9add1 Mon Sep 17 00:00:00 2001 From: Andrew McGivery Date: Tue, 8 Oct 2024 17:52:17 -0400 Subject: [PATCH 1/4] Add router config validate subcommand --- apollo-router/src/configuration/mod.rs | 3 ++- apollo-router/src/configuration/schema.rs | 3 --- apollo-router/src/executable.rs | 26 +++++++++++++++++++++++ docs/source/configuration/overview.mdx | 14 ++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/apollo-router/src/configuration/mod.rs b/apollo-router/src/configuration/mod.rs index 83d0e44a1e..e775feb3cb 100644 --- a/apollo-router/src/configuration/mod.rs +++ b/apollo-router/src/configuration/mod.rs @@ -42,9 +42,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 86bdee162f..9d319ab957 100644 --- a/apollo-router/src/executable.rs +++ b/apollo-router/src/executable.rs @@ -26,9 +26,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; @@ -140,6 +143,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/configuration/overview.mdx b/docs/source/configuration/overview.mdx index 0caa139fe9..5b8802d2c5 100644 --- a/docs/source/configuration/overview.mdx +++ b/docs/source/configuration/overview.mdx @@ -364,6 +364,7 @@ GraphOS Router and Apollo Router Core provide a set of subcommands for interacti ``` ./router config schema ./router config upgrade +./router config validate ``` @@ -406,6 +407,19 @@ 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. + +
From 946b9a781605bd4c80bf90e0c18130785b508c98 Mon Sep 17 00:00:00 2001 From: Andrew McGivery Date: Tue, 8 Oct 2024 17:55:05 -0400 Subject: [PATCH 2/4] Add changeset file --- .changesets/feat_feature_configvalidatesubcommand.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changesets/feat_feature_configvalidatesubcommand.md 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 From 002f82c14b4e6e658f356fcc865526f29dea005f Mon Sep 17 00:00:00 2001 From: Andrew McGivery Date: Wed, 8 Jan 2025 15:42:49 -0500 Subject: [PATCH 3/4] Docs update --- docs/source/reference/router/configuration.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/reference/router/configuration.mdx b/docs/source/reference/router/configuration.mdx index 5ce8df2be1..a2435bc70a 100644 --- a/docs/source/reference/router/configuration.mdx +++ b/docs/source/reference/router/configuration.mdx @@ -416,6 +416,8 @@ For details, see [Upgrading your router configuration](#upgrading-your-router-co 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 using the JSON schema. The router does additional logical checks on startup against the config that this command does not capture. + From f030cfa438adcb0ba0cb5d50462cfc5bc8d4ee95 Mon Sep 17 00:00:00 2001 From: Andrew McGivery Date: Mon, 13 Jan 2025 11:27:03 -0500 Subject: [PATCH 4/4] Update docs/source/reference/router/configuration.mdx Co-authored-by: Coenen Benjamin --- docs/source/reference/router/configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/reference/router/configuration.mdx b/docs/source/reference/router/configuration.mdx index a2435bc70a..83388d4a48 100644 --- a/docs/source/reference/router/configuration.mdx +++ b/docs/source/reference/router/configuration.mdx @@ -416,7 +416,7 @@ For details, see [Upgrading your router configuration](#upgrading-your-router-co 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 using the JSON schema. The router does additional logical checks on startup against the config that this command does not capture. +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.