Skip to content

Commit

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

/// Delete graph from a path `path` on the server
///
/// Arguments:
/// * `path`: the path of the graph to be deleted
///
/// Returns:
/// Delete status as boolean
#[pyo3(signature = (path))]
fn delete_graph(&self, path: String) -> PyResult<bool> {
let query = r#"
mutation DeleteGraph($path: String!) {
deleteGraph(
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("deleteGraph") {
Some(JsonValue::Bool(res)) => Ok((*res).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
20 changes: 20 additions & 0 deletions python/tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,26 @@ def test_delete_graph_succeeds_if_graph_found():
server.stop()


def test_delete_graph_using_client_api_succeeds_if_graph_found():
work_dir = tempfile.mkdtemp()
server = RaphtoryServer(work_dir).start()
client = RaphtoryClient("http://localhost:1736")

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"))

try:
client.delete_graph("g1")
except Exception as e:
assert "Graph not found ben/g5" in str(e), f"Unexpected exception message: {e}"

server.stop()


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

0 comments on commit 0804e1e

Please sign in to comment.