Skip to content

Commit

Permalink
Feature/gql sort nodes (#1912)
Browse files Browse the repository at this point in the history
* add sorting support for nodes in GraphQl

* add node sorting tests

* fix the python tests (submodules should start with test_

* implement sorting for list properties

* non-trivial test for list sorting

* fix warnings

* fmt
  • Loading branch information
ljeub-pometry authored Jan 15, 2025
1 parent 1df3b0c commit 3573dc5
Show file tree
Hide file tree
Showing 34 changed files with 599 additions and 89 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import tempfile

import pytest

from raphtory.graphql import GraphServer
from raphtory import Graph, PersistentGraph
import json
import re

PORT = 1737
from utils import run_graphql_test


def create_test_graph(g):
Expand Down Expand Up @@ -72,40 +67,12 @@ def create_test_graph(g):
return g


def run_graphql_test(query, expected_output, graph):
create_test_graph(graph)
tmp_work_dir = tempfile.mkdtemp()
with GraphServer(tmp_work_dir).start(PORT) as server:
client = server.get_client()
client.send_graph(path="g", graph=graph)

response = client.query(query)

# Convert response to a dictionary if needed and compare
response_dict = json.loads(response) if isinstance(response, str) else response
assert response_dict == expected_output


def run_graphql_error_test(query, expected_error_message, graph):
create_test_graph(graph)
tmp_work_dir = tempfile.mkdtemp()
with GraphServer(tmp_work_dir).start(PORT) as server:
client = server.get_client()
client.send_graph(path="g", graph=graph)

with pytest.raises(Exception) as excinfo:
client.query(query)

full_error_message = str(excinfo.value)
match = re.search(r'"message":"(.*?)"', full_error_message)
error_message = match.group(1) if match else ""
EVENT_GRAPH = create_test_graph(Graph())

assert (
error_message == expected_error_message
), f"Expected '{expected_error_message}', but got '{error_message}'"
PERSISTENT_GRAPH = create_test_graph(PersistentGraph())


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_nothing(graph):
query = """
query {
Expand Down Expand Up @@ -140,10 +107,10 @@ def test_graph_edge_sort_by_nothing(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_src(graph):
query = """
query {
Expand Down Expand Up @@ -178,10 +145,10 @@ def test_graph_edge_sort_by_src(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_dst(graph):
query = """
query {
Expand Down Expand Up @@ -216,10 +183,10 @@ def test_graph_edge_sort_by_dst(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_earliest_time(graph):
query = """
query {
Expand Down Expand Up @@ -254,10 +221,10 @@ def test_graph_edge_sort_by_earliest_time(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_earliest_time_reversed(graph):
query = """
query {
Expand Down Expand Up @@ -293,10 +260,10 @@ def test_graph_edge_sort_by_earliest_time_reversed(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH])
def test_graph_edge_sort_by_latest_time(graph):
query = """
query {
Expand Down Expand Up @@ -331,10 +298,10 @@ def test_graph_edge_sort_by_latest_time(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [PersistentGraph])
@pytest.mark.parametrize("graph", [PERSISTENT_GRAPH])
def test_graph_edge_sort_by_latest_time_persistent_graph(graph):
query = """
query {
Expand Down Expand Up @@ -370,10 +337,10 @@ def test_graph_edge_sort_by_latest_time_persistent_graph(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_eprop1(graph):
query = """
query {
Expand Down Expand Up @@ -408,10 +375,10 @@ def test_graph_edge_sort_by_eprop1(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_eprop2(graph):
query = """
query {
Expand Down Expand Up @@ -446,10 +413,10 @@ def test_graph_edge_sort_by_eprop2(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_eprop3(graph):
query = """
query {
Expand Down Expand Up @@ -484,10 +451,10 @@ def test_graph_edge_sort_by_eprop3(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_eprop4(graph):
query = """
query {
Expand Down Expand Up @@ -522,10 +489,10 @@ def test_graph_edge_sort_by_eprop4(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_eprop5(graph):
query = """
query {
Expand Down Expand Up @@ -560,10 +527,10 @@ def test_graph_edge_sort_by_eprop5(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_nonexistent_prop(graph):
query = """
query {
Expand Down Expand Up @@ -598,10 +565,10 @@ def test_graph_edge_sort_by_nonexistent_prop(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_combined(graph):
query = """
query {
Expand Down Expand Up @@ -636,10 +603,10 @@ def test_graph_edge_sort_by_combined(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)


@pytest.mark.parametrize("graph", [Graph, PersistentGraph])
@pytest.mark.parametrize("graph", [EVENT_GRAPH, PERSISTENT_GRAPH])
def test_graph_edge_sort_by_combined_2(graph):
query = """
query {
Expand Down Expand Up @@ -674,4 +641,4 @@ def test_graph_edge_sort_by_combined_2(graph):
}
}
}
run_graphql_test(query, expected_output, graph())
run_graphql_test(query, expected_output, graph)
Loading

0 comments on commit 3573dc5

Please sign in to comment.