feat: Make schema file path configurable in router registry plugin (#3751)

This commit is contained in:
Jonas Lergell 2024-01-09 10:06:00 +01:00 committed by GitHub
parent ec818f00c2
commit 1e783349f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -21,6 +21,7 @@ pub struct HiveRegistryConfig {
key: Option<String>,
poll_interval: Option<u64>,
accept_invalid_certs: Option<bool>,
schema_file_path: Option<String>,
}
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");

View file

@ -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`)
<Callout>
The `HIVE_CDN_ENDPOINT` variable should not include any artifact suffix (for example,