From ecefdfe8830ab9312add39744ba99f6fd7af7b91 Mon Sep 17 00:00:00 2001 From: matthew graham Date: Tue, 3 Sep 2024 18:20:30 -0400 Subject: [PATCH] keep stringified integer in the output fix the type on Resolution.path/1 incorporating PR feedback from @benwilson512 issue #1337 --- lib/absinthe/resolution.ex | 8 +++++--- test/absinthe/resolution/middleware_test.exs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/absinthe/resolution.ex b/lib/absinthe/resolution.ex index 9daf216515..a76f8d80f6 100644 --- a/lib/absinthe/resolution.ex +++ b/lib/absinthe/resolution.ex @@ -128,7 +128,7 @@ defmodule Absinthe.Resolution do In this case `5` is the 0 based index in the list of users the field is currently at. """ - @spec path(t()) :: [String.t()] + @spec path(t()) :: [String.t() | integer()] def path(%{path: path}) do path |> Enum.reverse() @@ -251,20 +251,22 @@ defmodule Absinthe.Resolution do ```elixir resolve fn _, _, resolution -> - Absinthe.Resolution.path(resolution) #=> ["email", "users", "RootQueryType"] + Absinthe.Resolution.path(resolution) #=> ["email", "0", "users", "RootQueryType"] end ``` """ @spec path_string(t()) :: [String.t()] def path_string(%__MODULE__{path: path}) do path - |> Enum.reject(fn x -> is_integer(x) end) |> Enum.map(fn %{name: name, alias: alias} -> alias || name %{schema_node: schema_node} -> schema_node.name + + n when is_integer(n) -> + Integer.to_string(n) end) end diff --git a/test/absinthe/resolution/middleware_test.exs b/test/absinthe/resolution/middleware_test.exs index 4276668d81..2fe7262736 100644 --- a/test/absinthe/resolution/middleware_test.exs +++ b/test/absinthe/resolution/middleware_test.exs @@ -198,7 +198,7 @@ defmodule Absinthe.MiddlewareTest do assert {:ok, %{data: data}} = Absinthe.run(doc, __MODULE__.Schema, context: %{current_user: %{}}) - assert %{"foo" => [%{"bar" => %{"result" => ["result", "bar", "foo", "RootQueryType"]}}]} == + assert %{"foo" => [%{"bar" => %{"result" => ["result", "bar", "0", "foo", "RootQueryType"]}}]} == data end end