Skip to content

Commit

Permalink
Fix passing args to transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
twist900 committed Sep 9, 2024
1 parent b72d16b commit 5fd6c7c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/phase/apply_transforms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ defmodule AbsintheHelpers.Phase.ApplyTransforms do
transform_module =
String.to_existing_atom("Elixir.AbsintheHelpers.Transforms.#{transform_camelized}Transform")

apply(transform_module, :call, [input | transform_args])
apply(transform_module, :call, [input, transform_args])

Check warning on line 157 in lib/phase/apply_transforms.ex

View workflow job for this annotation

GitHub Actions / Static Checks (Elixir 1.16.2)

Avoid `apply/2` and `apply/3` when the number of arguments is known.
end

defp get_transforms(private) do
Expand Down
2 changes: 1 addition & 1 deletion lib/transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ defmodule AbsintheHelpers.Transform do

alias Absinthe.Blueprint.Input

@callback call(Input.Value.t(), Keyword.t()) :: {:ok, Input.Value.t()} | {:error, atom()}
@callback call(Input.Value.t(), list()) :: {:ok, Input.Value.t()} | {:error, atom()}
end
9 changes: 7 additions & 2 deletions test/absinthe_helpers/phase/apply_transforms_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ defmodule AbsintheHelpers.Phase.ApplyTransformsTest do
field(:override_ids, non_null(list_of(non_null(:id)))) do
meta(transforms: [:trim, {:to_integer, true}])
end

field(:accumulator, :string, meta: [transforms: [:to_integer, {:increment, 3}]])
end

def run_query(query) do
Expand All @@ -52,7 +54,8 @@ defmodule AbsintheHelpers.Phase.ApplyTransformsTest do
customer_id: 1,
service: %{
employee_id: 456,
override_ids: [1, 2, 3]
override_ids: [1, 2, 3],
accumulator: 4
}
}

Expand All @@ -67,6 +70,7 @@ defmodule AbsintheHelpers.Phase.ApplyTransformsTest do
service: {
employee_id: "456",
override_ids: ["1", " 2", "3"]
accumulator: "1"
}
)
}
Expand All @@ -82,7 +86,8 @@ defmodule AbsintheHelpers.Phase.ApplyTransformsTest do
customer_id: "1",
service: {
employee_id: "456",
override_ids: ["1", "invalid_id", "3"]
override_ids: ["1", "invalid_id", "3"],
accumulator: "1"
}
)
}
Expand Down
9 changes: 9 additions & 0 deletions test/support/transforms/increment_transform.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule AbsintheHelpers.Transforms.IncrementTransform do

Check warning on line 1 in test/support/transforms/increment_transform.ex

View workflow job for this annotation

GitHub Actions / Static Checks (Elixir 1.16.2)

Modules should have a @moduledoc tag.
alias Absinthe.Blueprint.Input

@behaviour AbsintheHelpers.Transform

def call(%Input.Value{data: data} = item, [step]) do
{:ok, %{item | data: data + step}}
end
end

0 comments on commit 5fd6c7c

Please sign in to comment.