From dd75c42e4ebd73f12fc57b9f7b0e5194e6e5b1aa Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:24:29 +0100 Subject: [PATCH 1/3] expose encode graph --- raphtory-graphql/src/python/mod.rs | 7 ++----- raphtory-graphql/src/python/pymodule.rs | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/raphtory-graphql/src/python/mod.rs b/raphtory-graphql/src/python/mod.rs index 5067de2aff..df5ec984b9 100644 --- a/raphtory-graphql/src/python/mod.rs +++ b/raphtory-graphql/src/python/mod.rs @@ -1,10 +1,6 @@ use crate::url_encode::{url_encode_graph, UrlDecodeError}; use async_graphql::{dynamic::ValueAccessor, Value as GraphqlValue}; -use pyo3::{ - exceptions::{PyTypeError, PyValueError}, - types::PyDict, - IntoPy, PyErr, PyObject, PyResult, Python, ToPyObject, -}; +use pyo3::{exceptions::{PyTypeError, PyValueError}, types::PyDict, IntoPy, PyErr, PyObject, PyResult, Python, ToPyObject, pyfunction}; use raphtory::{db::api::view::MaterializedGraph, python::utils::errors::adapt_err_value}; use serde_json::{Map, Number, Value as JsonValue}; use std::collections::HashMap; @@ -107,6 +103,7 @@ fn translate_to_python(py: Python, value: serde_json::Value) -> PyResult PyResult { let result = url_encode_graph(graph); match result { diff --git a/raphtory-graphql/src/python/pymodule.rs b/raphtory-graphql/src/python/pymodule.rs index f86245db89..0f09e126f4 100644 --- a/raphtory-graphql/src/python/pymodule.rs +++ b/raphtory-graphql/src/python/pymodule.rs @@ -6,7 +6,8 @@ use crate::python::{ global_plugins::PyGlobalPlugins, server::{running_server::PyRunningGraphServer, server::PyGraphServer}, }; -use pyo3::{prelude::PyModule, PyErr, Python}; +use pyo3::{prelude::PyModule, PyErr, Python, wrap_pyfunction}; +use crate::python::encode_graph; pub fn base_graphql_module(py: Python<'_>) -> Result<&PyModule, PyErr> { let graphql_module = PyModule::new(py, "graphql")?; @@ -20,5 +21,8 @@ pub fn base_graphql_module(py: Python<'_>) -> Result<&PyModule, PyErr> { graphql_module.add_class::()?; graphql_module.add_class::()?; graphql_module.add_class::()?; + + graphql_module.add_function(wrap_pyfunction!(encode_graph, graphql_module)?)?; + Ok(graphql_module) } From 25a8e6b21f9121c6b85ab5fea1dbb174a4d35dcc Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:30:28 +0100 Subject: [PATCH 2/3] add test --- python/tests/graphql/edit_graph/test_graphql.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/tests/graphql/edit_graph/test_graphql.py b/python/tests/graphql/edit_graph/test_graphql.py index aa65bcb30e..0a56b396f0 100644 --- a/python/tests/graphql/edit_graph/test_graphql.py +++ b/python/tests/graphql/edit_graph/test_graphql.py @@ -3,7 +3,7 @@ import pytest -from raphtory.graphql import GraphServer, RaphtoryClient +from raphtory.graphql import GraphServer, RaphtoryClient, encode_graph from raphtory import graph_loader from raphtory import Graph import json @@ -13,6 +13,16 @@ def normalize_path(path): return path.replace("\\", "/") +def test_encode_graph(): + g = Graph() + g.add_edge(1, "ben", "hamza") + g.add_edge(2, "haaroon", "hamza") + g.add_edge(3, "ben", "haaroon") + + encoded = encode_graph(g) + assert encoded == "EgxaCgoIX2RlZmF1bHQSDBIKCghfZGVmYXVsdBoFCgNiZW4aCQoFaGFtemEYARoLCgdoYWFyb29uGAIiAhABIgYIAhABGAEiBBACGAIqAhoAKgQSAhABKgQSAhADKgIKACoGEgQIARABKgYSBAgBEAIqBAoCCAEqBhIECAIQAioGEgQIAhADKgQKAggCKgQ6AhABKgIyACoIOgYIARACGAEqBDICCAEqCDoGCAIQAxgCKgQyAggC" + + def test_failed_server_start_in_time(): tmp_work_dir = tempfile.mkdtemp() server = None From 0cf781da293c9fbe07c79f8758fb5ecdf10796ce Mon Sep 17 00:00:00 2001 From: Shivam Kapoor <4599890+iamsmkr@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:55:25 +0100 Subject: [PATCH 3/3] fmt --- raphtory-graphql/src/python/mod.rs | 7 ++++++- raphtory-graphql/src/python/pymodule.rs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/raphtory-graphql/src/python/mod.rs b/raphtory-graphql/src/python/mod.rs index df5ec984b9..bd23189bc9 100644 --- a/raphtory-graphql/src/python/mod.rs +++ b/raphtory-graphql/src/python/mod.rs @@ -1,6 +1,11 @@ use crate::url_encode::{url_encode_graph, UrlDecodeError}; use async_graphql::{dynamic::ValueAccessor, Value as GraphqlValue}; -use pyo3::{exceptions::{PyTypeError, PyValueError}, types::PyDict, IntoPy, PyErr, PyObject, PyResult, Python, ToPyObject, pyfunction}; +use pyo3::{ + exceptions::{PyTypeError, PyValueError}, + pyfunction, + types::PyDict, + IntoPy, PyErr, PyObject, PyResult, Python, ToPyObject, +}; use raphtory::{db::api::view::MaterializedGraph, python::utils::errors::adapt_err_value}; use serde_json::{Map, Number, Value as JsonValue}; use std::collections::HashMap; diff --git a/raphtory-graphql/src/python/pymodule.rs b/raphtory-graphql/src/python/pymodule.rs index 0f09e126f4..e7c2a574f5 100644 --- a/raphtory-graphql/src/python/pymodule.rs +++ b/raphtory-graphql/src/python/pymodule.rs @@ -3,11 +3,11 @@ use crate::python::{ raphtory_client::PyRaphtoryClient, remote_edge::PyRemoteEdge, remote_graph::PyRemoteGraph, remote_node::PyRemoteNode, PyEdgeAddition, PyNodeAddition, PyUpdate, }, + encode_graph, global_plugins::PyGlobalPlugins, server::{running_server::PyRunningGraphServer, server::PyGraphServer}, }; -use pyo3::{prelude::PyModule, PyErr, Python, wrap_pyfunction}; -use crate::python::encode_graph; +use pyo3::{prelude::PyModule, wrap_pyfunction, PyErr, Python}; pub fn base_graphql_module(py: Python<'_>) -> Result<&PyModule, PyErr> { let graphql_module = PyModule::new(py, "graphql")?;