Skip to content

Commit

Permalink
fix arrowgraph for gql
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-880 committed May 24, 2024
1 parent ae0111c commit 3653893
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions raphtory-graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ toml = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }

[features]
arrow = ["raphtory/arrow"]
82 changes: 79 additions & 3 deletions raphtory-graphql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ mod graphql_test {
use async_graphql::UploadValue;
use dynamic_graphql::{Request, Variables};
use raphtory::{
arrow::graph_impl::ArrowGraph,
db::{api::view::IntoDynamic, graph::views::deletion_graph::PersistentGraph},
prelude::*,
};
use serde_json::json;
use std::collections::HashMap;
use tempfile::tempdir;
use std::{collections::HashMap, path::Path};
use tempfile::{tempdir, TempDir};

#[tokio::test]
async fn search_for_gandalf_query() {
Expand All @@ -67,6 +68,7 @@ mod graphql_test {
)
.expect("Could not add node!");

let graph: MaterializedGraph = graph.into();
let graphs = HashMap::from([("lotr".to_string(), graph)]);
let data = Data::from_map(graphs);
let schema = App::create_schema().data(data).finish().unwrap();
Expand Down Expand Up @@ -105,6 +107,7 @@ mod graphql_test {
.add_node(0, 11, NO_PROPS, None)
.expect("Could not add node!");

let graph: MaterializedGraph = graph.into();
let graphs = HashMap::from([("lotr".to_string(), graph)]);
let data = Data::from_map(graphs);

Expand Down Expand Up @@ -152,7 +155,7 @@ mod graphql_test {
None,
)
.unwrap();

let graph: MaterializedGraph = graph.into();
let graphs = HashMap::from([("graph".to_string(), graph)]);
let data = Data::from_map(graphs);
let schema = App::create_schema().data(data).finish().unwrap();
Expand Down Expand Up @@ -474,4 +477,77 @@ mod graphql_test {
let graph_roundtrip = url_decode_graph(graph_encoded).unwrap().into_dynamic();
assert_eq!(g, graph_roundtrip);
}

#[cfg(feature = "arrow")]
#[tokio::test]
async fn test_arrow_graph() {
let graph = Graph::new();
graph.add_constant_properties([("name", "graph")]).unwrap();
graph.add_node(1, 1, NO_PROPS, Some("a")).unwrap();
graph.add_node(1, 2, NO_PROPS, Some("b")).unwrap();
graph.add_node(1, 3, NO_PROPS, Some("b")).unwrap();
graph.add_node(1, 4, NO_PROPS, Some("a")).unwrap();
graph.add_node(1, 5, NO_PROPS, Some("c")).unwrap();
graph.add_node(1, 6, NO_PROPS, Some("e")).unwrap();
graph.add_edge(22, 1, 2, NO_PROPS, Some("a")).unwrap();
graph.add_edge(22, 3, 2, NO_PROPS, Some("a")).unwrap();
graph.add_edge(22, 2, 4, NO_PROPS, Some("a")).unwrap();
graph.add_edge(22, 4, 5, NO_PROPS, Some("a")).unwrap();
graph.add_edge(22, 4, 5, NO_PROPS, Some("a")).unwrap();
graph.add_edge(22, 5, 6, NO_PROPS, Some("a")).unwrap();
graph.add_edge(22, 3, 6, NO_PROPS, Some("a")).unwrap();

let test_dir = TempDir::new().unwrap();
let arrow_graph = ArrowGraph::from_graph(&graph, test_dir.path()).unwrap();
let graph: MaterializedGraph = arrow_graph.into();

let graphs = HashMap::from([("graph".to_string(), graph)]);
let data = Data::from_map(graphs);
let schema = App::create_schema().data(data).finish().unwrap();

let req = r#"
{
graph(name: "graph") {
nodes {
list {
name
}
}
}
}
"#;

let req = Request::new(req);
let res = schema.execute(req).await;
let data = res.data.into_json().unwrap();
assert_eq!(
data,
json!({
"graph": {
"nodes": {
"list": [
{
"name": "1"
},
{
"name": "2"
},
{
"name": "3"
},
{
"name": "4"
},
{
"name": "5"
},
{
"name": "6"
}
]
}
}
}),
);
}
}
4 changes: 2 additions & 2 deletions raphtory-graphql/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod server_tests {
use chrono::prelude::*;
use raphtory::{
core::Prop,
prelude::{AdditionOps, Graph, GraphViewOps},
prelude::{AdditionOps, Graph},
};
use std::collections::HashMap;
use tokio::time::{sleep, Duration};
Expand All @@ -336,7 +336,7 @@ mod server_tests {
None,
)
.unwrap();
let g = graph.materialize().unwrap();
let g = graph.into();
let graphs = HashMap::from([("test".to_owned(), g)]);
let server = RaphtoryServer::from_map(graphs);
println!("calling start at time {}", Local::now());
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/arrow/graph_impl/core_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl CoreGraphOps for ArrowGraph {
}

fn node_type(&self, _v: VID) -> Option<ArcStr> {
todo!("Node types are not supported on arrow yet")
None
}

fn internalise_node(&self, v: NodeRef) -> Option<VID> {
Expand Down
Loading

0 comments on commit 3653893

Please sign in to comment.