From 669495e88cab95cdaff3ee6d3090fbcde83244e0 Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 12 Dec 2024 18:11:43 -0500 Subject: [PATCH] feat: Add space id filter --- Cargo.lock | 1 + api/Cargo.toml | 1 + api/src/main.rs | 17 +++++++++++++++-- codegen/src/lib.rs | 4 ++-- sdk/src/lib.rs | 2 ++ sink/src/kg/client.rs | 1 - 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f39f0ab..9b1c448 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,6 +137,7 @@ dependencies = [ "juniper", "juniper_axum", "juniper_graphql_ws", + "sdk", "serde", "serde_json", "serde_path_to_error", diff --git a/api/Cargo.toml b/api/Cargo.toml index 86a2433..b3c2a56 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -17,6 +17,7 @@ tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] } tracing = "0.1.41" tracing-subscriber = "0.3.19" +sdk = { version = "0.1.0", path = "../sdk" } sink = { version = "0.1.0", path = "../sink" } [dev-dependencies] diff --git a/api/src/main.rs b/api/src/main.rs index b038e59..233ae07 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -34,13 +34,22 @@ impl Query { &'a self, executor: &'a Executor<'_, '_, KnowledgeGraph, S>, id: String, - // context: &'a KnowledgeGraph, + space_id: Option, + version_id: Option, ) -> Option { // let query = QueryMapper::default().select_root_node(&id, &executor.look_ahead()).build(); // tracing::info!("Query: {}", query); + let query = match (space_id, version_id) { + (Some(space_id), _) => sdk::neo4rs::query("MATCH (n {id: $id, space_id: $space_id}) RETURN n") + .param("id", id) + .param("space_id", space_id), + (None, _) => sdk::neo4rs::query("MATCH (n {id: $id}) RETURN n") + .param("id", id) + }; + executor.context().0 - .find_node_by_id::>(&id) + .find_node::>(query) .await .expect("Failed to find node") .map(Node::from) @@ -116,6 +125,10 @@ impl Node { &self.id } + fn space_id(&self) -> &str { + &self.space_id + } + fn types(&self) -> &[String] { &self.types } diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index c98e173..c38b5f9 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -39,7 +39,7 @@ pub fn ts_type_from_value_type(value_type: &Node) -> TsType { } } -pub fn gen_type_constructor(kg: &sink::kg::Client, attributes: &[&(Node, Option>)]) -> Constructor { +pub fn gen_type_constructor(attributes: &[&(Node, Option>)]) -> Constructor { let super_constructor = vec![quote_expr!("super(id, driver)")]; let constuctor_setters = attributes.iter().map(|(attr, _)| { @@ -225,7 +225,7 @@ pub async fn gen_type(kg: &sink::kg::Client, entity: &Node) -> anyhow::Re Ok(Decl::Class(class( entity.type_name(), attribute_class_props, - Some(gen_type_constructor(kg, &attributes)), + Some(gen_type_constructor(&attributes)), relation_methods, vec![], Some(ident("Entity")), diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 64582cc..741a73f 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -8,3 +8,5 @@ pub mod relation; pub use ids::network_ids; pub use ids::system_ids; + +pub use neo4rs; diff --git a/sink/src/kg/client.rs b/sink/src/kg/client.rs index 8eeba77..f2fe32c 100644 --- a/sink/src/kg/client.rs +++ b/sink/src/kg/client.rs @@ -608,7 +608,6 @@ impl Client { .next() .await? .map(|row| { - tracing::info!("Row: {:?}", row.to::()); Ok::<_, DatabaseError>(Relation::::try_from(row.to::()?)?) }) .transpose()?)