From 1e783349f3b7a3e8c2cd2f5e955798a64ed2b30e Mon Sep 17 00:00:00 2001 From: Jonas Lergell Date: Tue, 9 Jan 2024 10:06:00 +0100 Subject: [PATCH] feat: Make schema file path configurable in router registry plugin (#3751) --- packages/libraries/router/src/registry.rs | 11 ++++++++++- .../src/pages/docs/integrations/apollo-router.mdx | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/libraries/router/src/registry.rs b/packages/libraries/router/src/registry.rs index e2fd214b9..49de1a368 100644 --- a/packages/libraries/router/src/registry.rs +++ b/packages/libraries/router/src/registry.rs @@ -21,6 +21,7 @@ pub struct HiveRegistryConfig { key: Option, poll_interval: Option, accept_invalid_certs: Option, + schema_file_path: Option, } static COMMIT: Option<&'static str> = option_env!("GITHUB_SHA"); @@ -32,6 +33,7 @@ impl HiveRegistry { key: None, poll_interval: None, accept_invalid_certs: Some(true), + schema_file_path: None }; // Pass values from user's config @@ -40,6 +42,7 @@ impl HiveRegistry { config.key = user_config.key; config.poll_interval = user_config.poll_interval; config.accept_invalid_certs = user_config.accept_invalid_certs; + config.schema_file_path = user_config.schema_file_path; } // Pass values from environment variables if they are not set in the user's config @@ -76,6 +79,12 @@ impl HiveRegistry { } } + if config.schema_file_path.is_none() { + if let Ok(schema_file_path) = env::var("HIVE_CDN_SCHEMA_FILE_PATH") { + config.schema_file_path = Some(schema_file_path); + } + } + // Resolve values let endpoint = config.endpoint.unwrap_or_else(|| "".to_string()); let key = config.key.unwrap_or_else(|| "".to_string()); @@ -109,7 +118,7 @@ impl HiveRegistry { // A hacky way to force the router to use GraphQL Hive CDN as the source of schema. // Our plugin does the polling and saves the supergraph to a file. // It also enables hot-reloading to makes sure Apollo Router watches the file. - let file_name = "supergraph-schema.graphql".to_string(); + let file_name = config.schema_file_path.unwrap_or("supergraph-schema.graphql".to_string()); env::set_var("APOLLO_ROUTER_SUPERGRAPH_PATH", file_name.clone()); env::set_var("APOLLO_ROUTER_HOT_RELOAD", "true"); diff --git a/packages/web/docs/src/pages/docs/integrations/apollo-router.mdx b/packages/web/docs/src/pages/docs/integrations/apollo-router.mdx index 2dbaca6a8..0ae2b8e74 100644 --- a/packages/web/docs/src/pages/docs/integrations/apollo-router.mdx +++ b/packages/web/docs/src/pages/docs/integrations/apollo-router.mdx @@ -130,6 +130,7 @@ used for authenticating the supergraph polling from the CDN. - `HIVE_CDN_POLL_INTERVAL` - polling interval (default is 10 seconds) - `HIVE_CDN_ACCEPT_INVALID_CERTS` - accepts invalid SSL certificates (default is `false`) - `HIVE_REGISTRY_LOG` - defines the log level for the registry (default is `INFO`) +- `HIVE_CDN_SCHEMA_FILE_PATH` - where to download the supergraph schema (default is `./supergraph-schema.graphql`) The `HIVE_CDN_ENDPOINT` variable should not include any artifact suffix (for example,