From 7e485bd72a287b9f007f5c1054db35ed9aa5fd8e Mon Sep 17 00:00:00 2001 From: illia-kuznietsov-introduct Date: Thu, 11 Sep 2025 12:24:31 +0300 Subject: [PATCH 1/6] added a new function to support elementMap() --- lib/gremlex/graph.ex | 10 ++++++++++ test/graph_test.exs | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/gremlex/graph.ex b/lib/gremlex/graph.ex index 2bdfb99..ce5f76c 100644 --- a/lib/gremlex/graph.ex +++ b/lib/gremlex/graph.ex @@ -182,6 +182,16 @@ defmodule Gremlex.Graph do enqueue(graph, "valueMap", values) end + @doc """ + Appends elementMap command to the traversal. + Returns a graph to allow chaining. + """ + @spec element_map(Gremlex.Graph.t(), String.t() | list(String.t())) :: Gremlex.Graph.t() + def element_map(graph, values) when is_list(values), do: enqueue(graph, "elementMap", values) + def element_map(graph, value), do: enqueue(graph, "elementMap", [value]) + @spec element_map(Gremlex.Graph.t()) :: Gremlex.Graph.t() + def element_map(graph), do: enqueue(graph, "elementMap", []) + @doc """ Appends values command to the traversal. Returns a graph to allow chaining. diff --git a/test/graph_test.exs b/test/graph_test.exs index 7e27ff4..7c6ac2f 100644 --- a/test/graph_test.exs +++ b/test/graph_test.exs @@ -247,6 +247,26 @@ defmodule Gremlex.GraphTests do end end + describe "element_map" do + test "adds an elementMap function to the queue" do + actual_graph = g() |> Graph.element_map() + expected_graph = Queue.in({"elementMap", []}, Queue.new()) + assert actual_graph == expected_graph + end + + test "adds an elementMap function to the queue with a single property" do + actual_graph = g() |> Graph.element_map("hello") + expected_graph = Queue.in({"elementMap", ["hello"]}, Queue.new()) + assert actual_graph == expected_graph + end + + test "adds an elementMap function to the queue with list of properties" do + actual_graph = g() |> Graph.element_map(["foo", "bar"]) + expected_graph = Queue.in({"elementMap", ["foo", "bar"]}, Queue.new()) + assert actual_graph == expected_graph + end + end + describe "values/2" do test "adds a value function the queue" do actual_graph = g() |> values("foo") From 3edaaf5f531db1b1135df0f783c48592fc96a056 Mon Sep 17 00:00:00 2001 From: illia-kuznietsov-introduct Date: Thu, 11 Sep 2025 12:32:24 +0300 Subject: [PATCH 2/6] version update --- CHANGELOG.md | 3 +++ mix.exs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f3b4f2..2a0240d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Unreleased +## 0.4.10 [2025-09-11] +- Added support for `elementMap()` traversal step via `Gremlex.Graph.element_map/1` and `Gremlex.Graph.element_map/2` functions + ## 0.4.9 [2025-09-11] - Handle multiple pong messages in a query response. diff --git a/mix.exs b/mix.exs index de20b86..d76453f 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule Gremlex.MixProject do use Mix.Project @source_url "https://github.com/coingaming/gremlex" - @version "0.4.9" + @version "0.4.10" def project do [ From 27c6c12ac89e2731511020b7c6e808b3b167f574 Mon Sep 17 00:00:00 2001 From: illia-kuznietsov-introduct Date: Thu, 11 Sep 2025 13:19:25 +0300 Subject: [PATCH 3/6] addressed comments --- CHANGELOG.md | 2 +- lib/gremlex/graph.ex | 6 +++--- test/graph_test.exs | 17 ++++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a0240d..3cec611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Unreleased ## 0.4.10 [2025-09-11] -- Added support for `elementMap()` traversal step via `Gremlex.Graph.element_map/1` and `Gremlex.Graph.element_map/2` functions +- Add support for `elementMap()` traversal step via `Gremlex.Graph.element_map/1` and `Gremlex.Graph.element_map/2` functions ## 0.4.9 [2025-09-11] - Handle multiple pong messages in a query response. diff --git a/lib/gremlex/graph.ex b/lib/gremlex/graph.ex index ce5f76c..d5b5437 100644 --- a/lib/gremlex/graph.ex +++ b/lib/gremlex/graph.ex @@ -184,12 +184,12 @@ defmodule Gremlex.Graph do @doc """ Appends elementMap command to the traversal. - Returns a graph to allow chaining. """ - @spec element_map(Gremlex.Graph.t(), String.t() | list(String.t())) :: Gremlex.Graph.t() + @spec element_map(t(), String.t() | list(String.t())) :: Graph.t() def element_map(graph, values) when is_list(values), do: enqueue(graph, "elementMap", values) def element_map(graph, value), do: enqueue(graph, "elementMap", [value]) - @spec element_map(Gremlex.Graph.t()) :: Gremlex.Graph.t() + + @spec element_map(t()) :: t() def element_map(graph), do: enqueue(graph, "elementMap", []) @doc """ diff --git a/test/graph_test.exs b/test/graph_test.exs index 7c6ac2f..1f98a94 100644 --- a/test/graph_test.exs +++ b/test/graph_test.exs @@ -247,23 +247,22 @@ defmodule Gremlex.GraphTests do end end - describe "element_map" do + describe "element_map/1" do test "adds an elementMap function to the queue" do - actual_graph = g() |> Graph.element_map() - expected_graph = Queue.in({"elementMap", []}, Queue.new()) - assert actual_graph == expected_graph + actual_graph = g() |> v() |> Graph.element_map() + assert encode(actual_graph) == "g.V().elementMap()" end + end + describe "element_map/2" do test "adds an elementMap function to the queue with a single property" do - actual_graph = g() |> Graph.element_map("hello") - expected_graph = Queue.in({"elementMap", ["hello"]}, Queue.new()) - assert actual_graph == expected_graph + actual_graph = g() | v() |> Graph.element_map("hello") + assert encode(actual_graph) == "g.V().elementMap('hello')" end test "adds an elementMap function to the queue with list of properties" do actual_graph = g() |> Graph.element_map(["foo", "bar"]) - expected_graph = Queue.in({"elementMap", ["foo", "bar"]}, Queue.new()) - assert actual_graph == expected_graph + assert encode(actual_graph) == "g.V().elementMap('foo', 'bar')" end end From 311b711177d170896b36dbf7496871d241f27c05 Mon Sep 17 00:00:00 2001 From: illia-kuznietsov-introduct Date: Thu, 11 Sep 2025 13:21:03 +0300 Subject: [PATCH 4/6] spec fix --- lib/gremlex/graph.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gremlex/graph.ex b/lib/gremlex/graph.ex index d5b5437..2ad50cc 100644 --- a/lib/gremlex/graph.ex +++ b/lib/gremlex/graph.ex @@ -185,7 +185,7 @@ defmodule Gremlex.Graph do @doc """ Appends elementMap command to the traversal. """ - @spec element_map(t(), String.t() | list(String.t())) :: Graph.t() + @spec element_map(t(), String.t() | list(String.t())) :: t() def element_map(graph, values) when is_list(values), do: enqueue(graph, "elementMap", values) def element_map(graph, value), do: enqueue(graph, "elementMap", [value]) From fc2a393a3f1105c270b90aca7e6cbb9e94715f51 Mon Sep 17 00:00:00 2001 From: illia-kuznietsov-introduct Date: Thu, 11 Sep 2025 13:23:30 +0300 Subject: [PATCH 5/6] brain fart on test fix --- test/graph_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/graph_test.exs b/test/graph_test.exs index 1f98a94..4be5a57 100644 --- a/test/graph_test.exs +++ b/test/graph_test.exs @@ -256,12 +256,12 @@ defmodule Gremlex.GraphTests do describe "element_map/2" do test "adds an elementMap function to the queue with a single property" do - actual_graph = g() | v() |> Graph.element_map("hello") + actual_graph = g() |> v() |> Graph.element_map("hello") assert encode(actual_graph) == "g.V().elementMap('hello')" end test "adds an elementMap function to the queue with list of properties" do - actual_graph = g() |> Graph.element_map(["foo", "bar"]) + actual_graph = g() |> v() |> Graph.element_map(["foo", "bar"]) assert encode(actual_graph) == "g.V().elementMap('foo', 'bar')" end end From 760539c20b60ce8efbb1a90b5a6e4ddac5cdc708 Mon Sep 17 00:00:00 2001 From: illia-kuznietsov-introduct Date: Thu, 11 Sep 2025 13:31:51 +0300 Subject: [PATCH 6/6] Update CHANGELOG.md Co-authored-by: Ignacio Goldchluk --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cec611..ec13df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Unreleased ## 0.4.10 [2025-09-11] + +### Added - Add support for `elementMap()` traversal step via `Gremlex.Graph.element_map/1` and `Gremlex.Graph.element_map/2` functions ## 0.4.9 [2025-09-11]