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

Save as #1268

Merged
merged 3 commits into from
Sep 18, 2023
Merged

Save as #1268

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions raphtory-graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tracing-opentelemetry = "0.18.0"
tracing-subscriber = {version = "0.3.16", features = ["std", "env-filter"]}
walkdir = "2"
ordered-float = "3.7.0"
uuid = "1.4.1"

[dev-dependencies]
serde_json = "1.0"
Expand Down
52 changes: 41 additions & 11 deletions raphtory-graphql/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use std::{
collections::HashMap,
error::Error,
fmt::{Display, Formatter},
io::BufReader,
ops::Deref,
};

use crate::{
data::Data,
model::graph::graph::{GqlGraph, GraphMeta},
Expand All @@ -23,6 +15,14 @@ use raphtory::{
prelude::{Graph, GraphViewOps, PropertyAdditionOps},
search::IndexedGraph,
};
use std::{
collections::HashMap,
error::Error,
fmt::{Display, Formatter},
io::BufReader,
ops::Deref,
};
use uuid::Uuid;

pub(crate) mod algorithm;
pub(crate) mod filters;
Expand Down Expand Up @@ -113,25 +113,55 @@ impl Mut {
ctx: &Context<'a>,
parent_graph_name: String,
graph_name: String,
new_graph_name: String,
props: String,
graph_nodes: Vec<String>,
) -> Result<bool> {
let mut data = ctx.data_unchecked::<Data>().graphs.write();

let subgraph = data.get(&graph_name).ok_or("Graph not found")?;
let path = subgraph
let mut path = subgraph
.static_prop(&"path".to_string())
.expect("Path is missing")
.to_string();

if new_graph_name.ne(&graph_name) {
fn path_prefix(path: String) -> Result<String> {
let elements: Vec<&str> = path.split('/').collect();
let size = elements.len();
return if size > 2 {
let delimiter = "/";
let joined_string = elements
.iter()
.take(size - 1)
.map(|s| *s)
.collect::<Vec<_>>()
.join(delimiter);
Ok(joined_string)
} else {
Err("Invalid graph path".into())
};
}

path = path_prefix(path)? + "/" + &Uuid::new_v4().hyphenated().to_string();
}

let parent_graph = data.get(&parent_graph_name).ok_or("Graph not found")?;
let new_subgraph = parent_graph
.subgraph(graph_nodes)
.materialize()
.expect("Failed to materialize graph");
let static_props_without_name: Vec<(String, Prop)> = subgraph
.properties()
.into_iter()
.filter(|(a, b)| a != "name")
.collect_vec();
new_subgraph
.add_constant_properties(subgraph.properties().constant())
.add_constant_properties(static_props_without_name)
.expect("Failed to add static properties");
new_subgraph
.add_constant_properties([("name".to_string(), Prop::Str(new_graph_name.clone()))])
.expect("Failed to add static property");
new_subgraph
.add_constant_properties([("uiProps".to_string(), Prop::Str(props))])
.expect("Failed to add static property");
Expand All @@ -145,7 +175,7 @@ impl Mut {
.ok_or("Graph with deletions not supported")?
.into();

data.insert(graph_name.clone(), gi.clone());
data.insert(new_graph_name, gi.clone());

Ok(true)
}
Expand Down