Skip to content
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

Add failing test for ParseIDs middleware inside mutation #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions test/lib/absinthe/relay/node/parse_ids_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ defmodule Absinthe.Relay.Node.ParseIDsTest do
field :name, :string
field :children, list_of(:child)
field :child, :child

field :child_by_id, :child do
arg :id, :id
middleware Absinthe.Relay.Node.ParseIDs, id: :child
resolve &resolve_child_by_id/3
end
end

node object(:child) do
Expand Down Expand Up @@ -175,6 +181,11 @@ defmodule Absinthe.Relay.Node.ParseIDsTest do
{:ok, values}
end

defp resolve_child_by_id(%{children: children}, %{id: id}, _) do
child = Enum.find(children, &(&1.id === id))
{:ok, child}
end

defp resolve_parent(args, _) do
{:ok, args |> to_parent_output}
end
Expand Down Expand Up @@ -487,6 +498,40 @@ defmodule Absinthe.Relay.Node.ParseIDsTest do

assert {:ok, %{data: %{"updateParent" => expected_parent_data}}} == result
end

test "works with nested id args" do
result =
"""
mutation Foobar {
updateParent(input: {
clientMutationId: "abc",
parent: {
id: "#{@parent1_id}",
children: [{ id: "#{@child1_id}"}, {id: "#{@child2_id}"}],
child: { id: "#{@child2_id}"}
}
}) {
parent {
id
childById(id: "#{@child2_id}") { id }
}
}
}
"""
|> Absinthe.run(SchemaClassic)

expected_parent_data = %{
"parent" => %{
# The output re-converts everything to global_ids.
"id" => @parent1_id,
"childById" => %{
"id" => @child2_id
}
}
}

assert {:ok, %{data: %{"updateParent" => expected_parent_data}}} == result
end
end

test "parses incorrect nested ids" do
Expand Down