8000 expose encode graph by shivamka1 · Pull Request #1812 · Pometry/Raphtory · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

expose encode graph #1812

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

Merged
merged 5 commits into from
Oct 9, 2024
Merged
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
12 changes: 11 additions & 1 deletion python/tests/graphql/edit_graph/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions raphtory-graphql/src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::url_encode::{url_encode_graph, UrlDecodeError};
use async_graphql::{dynamic::ValueAccessor, Value as GraphqlValue};
use pyo3::{
exceptions::{PyTypeError, PyValueError},
pyfunction,
types::PyDict,
IntoPy, PyErr, PyObject, PyResult, Python, ToPyObject,
};
Expand Down Expand Up @@ -107,6 +108,7 @@ fn translate_to_python(py: Python, value: serde_json::Value) -> PyResult<PyObjec
}
}

#[pyfunction]
pub(crate) fn encode_graph(graph: MaterializedGraph) -> PyResult<String> {
let result = url_encode_graph(graph);
match result {
Expand Down
6 changes: 5 additions & 1 deletion raphtory-graphql/src/python/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +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};
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")?;
Expand All @@ -20,5 +21,8 @@ pub fn base_graphql_module(py: Python<'_>) -> Result<&PyModule, PyErr> {
graphql_module.add_class::<PyNodeAddition>()?;
graphql_module.add_class::<PyUpdate>()?;
graphql_module.add_class::<PyEdgeAddition>()?;

graphql_module.add_function(wrap_pyfunction!(encode_graph, graphql_module)?)?;

Ok(graphql_module)
}
Loading
0