From c281cf6f626c234bded13f36bb3d0c467ba2430e Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Tue, 15 Oct 2024 02:14:17 +0100 Subject: [PATCH] feat: allow rust project to override the environment file path --- core/src/generator/build.rs | 1 + core/src/indexer/no_code.rs | 4 ++++ core/src/start.rs | 5 ++++- documentation/docs/pages/docs/changelog.mdx | 1 + .../docs/start-building/rust-project-deep-dive/indexers.mdx | 1 + rindexer_rust_playground/src/main.rs | 1 + 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/generator/build.rs b/core/src/generator/build.rs index 47a1ef21..d8b73ac3 100644 --- a/core/src/generator/build.rs +++ b/core/src/generator/build.rs @@ -440,6 +440,7 @@ serde = {{ version = "1.0.194", features = ["derive"] }} let manifest_path = path.join("rindexer.yaml"); let result = start_rindexer(StartDetails { manifest_path: &manifest_path, + override_environment_path: None, indexing_details: if enable_indexer { Some(IndexingDetails { registry: register_all_handlers(&manifest_path).await, diff --git a/core/src/indexer/no_code.rs b/core/src/indexer/no_code.rs index dae75a91..a3a2defb 100644 --- a/core/src/indexer/no_code.rs +++ b/core/src/indexer/no_code.rs @@ -84,6 +84,8 @@ pub async fn setup_no_code( if !details.indexing_details.enabled { return Ok(StartDetails { manifest_path: details.manifest_path, + // TODO: enable ability to override this for no-code projects + override_environment_path: None, indexing_details: None, graphql_details: details.graphql_details, }); @@ -115,6 +117,8 @@ pub async fn setup_no_code( Ok(StartDetails { manifest_path: details.manifest_path, + // TODO: enable ability to override this for no-code projects + override_environment_path: None, indexing_details: Some(IndexingDetails { registry }), graphql_details: details.graphql_details, }) diff --git a/core/src/start.rs b/core/src/start.rs index f4e7f8ac..bb12b73d 100644 --- a/core/src/start.rs +++ b/core/src/start.rs @@ -32,6 +32,7 @@ pub struct IndexingDetails { pub struct StartDetails<'a> { pub manifest_path: &'a PathBuf, + pub override_environment_path: Option<&'a PathBuf>, pub indexing_details: Option, pub graphql_details: GraphqlOverrideSettings, } @@ -78,7 +79,9 @@ pub async fn start_rindexer(details: StartDetails<'_>) -> Result<(), StartRindex let project_path = details.manifest_path.parent(); match project_path { Some(project_path) => { - load_env_from_path(project_path); + let env_path = + details.override_environment_path.map(PathBuf::as_path).unwrap_or(project_path); + load_env_from_path(env_path); let manifest = Arc::new(read_manifest(details.manifest_path)?); if manifest.project_type != ProjectType::NoCode { diff --git a/documentation/docs/pages/docs/changelog.mdx b/documentation/docs/pages/docs/changelog.mdx index f1b94052..d1af74a0 100644 --- a/documentation/docs/pages/docs/changelog.mdx +++ b/documentation/docs/pages/docs/changelog.mdx @@ -10,6 +10,7 @@ - feat: expose postgres ToSql trait - feat: support with_transaction in postgres client - feat: get the block timestamp from the RPC call (its an option as not all providers expose it) +- feat: allow rust project to override the environment file path ### Bug fixes ------------------------------------------------- diff --git a/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx b/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx index 6c1971f6..a5d123be 100644 --- a/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx +++ b/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx @@ -992,6 +992,7 @@ async fn main() { let manifest_path = path.join("rindexer.yaml"); let result = start_rindexer(StartDetails { manifest_path: &manifest_path, + override_environment_path: None, indexing_details: if enable_indexer { Some(IndexingDetails { registry: register_all_handlers(&manifest_path).await, diff --git a/rindexer_rust_playground/src/main.rs b/rindexer_rust_playground/src/main.rs index c828cd99..04ecfff8 100644 --- a/rindexer_rust_playground/src/main.rs +++ b/rindexer_rust_playground/src/main.rs @@ -55,6 +55,7 @@ async fn main() { let manifest_path = path.join("rindexer.yaml"); let result = start_rindexer(StartDetails { manifest_path: &manifest_path, + override_environment_path: None, indexing_details: if enable_indexer { // EventCallbackRegistry { events: vec![] } Some(IndexingDetails { registry: register_all_handlers(&manifest_path).await })