Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dotenv to allow router to read environment variables from .env file #6117

Closed
13 changes: 13 additions & 0 deletions .changesets/feat_feature_dotenv.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ dependencies = [
"dhat",
"diff",
"displaydoc",
"dotenvy",
"ecdsa",
"flate2",
"fred",
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions apollo-router/src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading