diff --git a/.changesets/feat_feature_dotenv.md b/.changesets/feat_feature_dotenv.md new file mode 100644 index 0000000000..03764c34eb --- /dev/null +++ b/.changesets/feat_feature_dotenv.md @@ -0,0 +1,13 @@ +### Add dotenv to allow router to read environment variables from .env file ([PR #6117](https://github.com/apollographql/router/pull/6117)) + +Router will now read environment variables from `.env` file. This is helpful for local development to inject in `APOLLO_KEY` and `APOLLO_GRAPH_REF` from a `.env` file. It also makes these environment variables available everywhere they are currently available such as in rhai scripts: + +``` +# .env +MY_COOL_VARIABLE="yeaaaaa man!" + +# main.rhai +log_info(`MY_COOL_VARIABLE: ${env::get("MY_COOL_VARIABLE")}`); +``` + +By [@andrewmcgivery](https://github.com/andrewmcgivery) in https://github.com/apollographql/router/pull/6117 diff --git a/Cargo.lock b/Cargo.lock index 8b422db473..498572ee5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,6 +267,7 @@ dependencies = [ "dhat", "diff", "displaydoc", + "dotenvy", "ecdsa", "flate2", "fred", @@ -2250,6 +2251,12 @@ dependencies = [ "syn 2.0.76", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "downcast" version = "0.11.0" diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index ff09306e2a..f92f6b002a 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -272,6 +272,7 @@ bytesize = { version = "1.3.0", features = ["serde"] } ahash = "0.8.11" itoa = "1.0.9" ryu = "1.0.15" +dotenvy = "0.15.7" [target.'cfg(macos)'.dependencies] uname = "0.1.1" diff --git a/apollo-router/src/executable.rs b/apollo-router/src/executable.rs index 86bdee162f..182388fd2f 100644 --- a/apollo-router/src/executable.rs +++ b/apollo-router/src/executable.rs @@ -331,6 +331,8 @@ pub fn main() -> Result<()> { #[cfg(feature = "dhat-ad-hoc")] create_ad_hoc_profiler(); + dotenvy::dotenv()?; + let mut builder = tokio::runtime::Builder::new_multi_thread(); builder.enable_all(); if let Some(nb) = std::env::var("APOLLO_ROUTER_NUM_CORES")