Skip to content

Commit

Permalink
receive graph helper
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-880 committed Jul 29, 2024
1 parent 0804e1e commit 56468f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
23 changes: 23 additions & 0 deletions python/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,29 @@ impl PyRaphtoryClient {
))),
}
}

/// Receive graph from a path `path` on the server
///
/// Arguments:
/// * `path`: the path of the graph to be received
///
/// Returns:
/// Graph as string
fn receive_graph(&self, path: String) -> PyResult<String> {
let query = r#"
query ReceiveGraph($path: String!) {
receiveGraph(path: $path)
}"#
.to_owned();
let variables = [("path".to_owned(), json!(path))];
let data = self.query_with_json_variables(query.clone(), variables.into())?;
match data.get("receiveGraph") {
Some(JsonValue::String(graph)) => Ok(graph.clone()),
_ => Err(PyException::new_err(format!(
"Error while reading server response for query:\n\t{query}\nGot data:\n\t'{data:?}'"
))),
}
}
}

fn translate_from_python(py: Python, value: PyObject) -> PyResult<JsonValue> {
Expand Down
24 changes: 24 additions & 0 deletions python/tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,30 @@ def test_receive_graph_succeeds_if_graph_found():
server.stop()


def test_receive_graph_using_client_api_succeeds_if_graph_found():
work_dir = tempfile.mkdtemp()
server = RaphtoryServer(work_dir).start()
client = server.get_client()

g = Graph()
g.add_edge(1, "ben", "hamza")
g.add_edge(2, "haaroon", "hamza")
g.add_edge(3, "ben", "haaroon")

g.save_to_file(os.path.join(work_dir, "g1"))

received_graph = 'AQAAAAAAAAADAAAAAAAAAJTXBAscINjlAQAAAAAAAADv0+QnEcpEzAIAAAAAAAAArUhReOzDmFAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAABAAAAAAAAAK1IUXjsw5hQAQMAAAAAAAAAYmVuAAAAAAAAAAACAAAAAgAAAAAAAAABAAAAAAAAAAMAAAAAAAAAAQAAAAAAAAABAAAAAgAAAAIAAAAAAAAAAQAA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AAAAAgAAAAAAAAAX2RlZmF1bHQAAAAAAAAAAAEAAAAAAAAACAAAAAAAAABfZGVmYXVsdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACAAAAAAAAABfZGVmYXVsdAAAAAAAAAAAAQAAAAAAAAAIAAAAAAAAAF9kZWZhdWx0AQAAAAAAAAAIAAAAAAAAAF9kZWZhdWx0AAAAAAAAAAABAAAAAAAAAAgAAAAAAAAAX2RlZmF1bHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='

assert client.receive_graph("g1") == received_graph

decoded_bytes = base64.b64decode(received_graph)

g = Graph.from_bincode(decoded_bytes)
assert g.nodes.name == ["ben", "hamza", "haaroon"]

server.stop()


def test_receive_graph_fails_if_no_graph_found_at_namespace():
work_dir = tempfile.mkdtemp()
server = RaphtoryServer(work_dir).start()
Expand Down

0 comments on commit 56468f1

Please sign in to comment.