diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f3b4f2..ec13df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## 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] - Handle multiple pong messages in a query response. diff --git a/lib/gremlex/graph.ex b/lib/gremlex/graph.ex index 2bdfb99..2ad50cc 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. + """ + @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]) + + @spec element_map(t()) :: 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/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 [ diff --git a/test/graph_test.exs b/test/graph_test.exs index 7e27ff4..4be5a57 100644 --- a/test/graph_test.exs +++ b/test/graph_test.exs @@ -247,6 +247,25 @@ defmodule Gremlex.GraphTests do end end + describe "element_map/1" do + test "adds an elementMap function to the queue" do + 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() |> 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() |> v() |> Graph.element_map(["foo", "bar"]) + assert encode(actual_graph) == "g.V().elementMap('foo', 'bar')" + end + end + describe "values/2" do test "adds a value function the queue" do actual_graph = g() |> values("foo")