Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions test/resource_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,38 @@

assert List.first(data)["rank"] < List.last(data)["rank"]
end

test "can use argument in filter and sort on calculated field" do

Check failure on line 191 in test/resource_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci / mix test

test can use argument in filter and sort on calculated field (AshGraphql.ResourceTest)
[
"a",
"b",
"c"
]
|> Enum.each(fn text ->
Ash.Seed.seed!(%AshGraphql.Test.Comment{text: text})
end)

Ash.read!(AshGraphql.Test.Comment, load: [:timestamp, arg_returned: [seconds: 10]])
|> Enum.each(fn %{arg_returned: arg_returned} ->
assert 10 = arg_returned
end)

assert {:ok, %{data: %{"listComments" => comments}}} =
"""
query {
listComments(
filter: {argReturned: {input: {seconds: 10}}}
sort: {argReturnedInput: {seconds: 10}, field: ARG_RETURNED, order: ASC_NULLS_LAST}
) {
text
argReturned(seconds: 10)
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema)

Enum.each(comments, fn %{"arg_returned" => arg_returned} ->
assert 10 = arg_returned
end)
end
end
7 changes: 7 additions & 0 deletions test/support/resources/comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ defmodule AshGraphql.Test.Comment do
expr(created_at),
public?: true
)

calculate :arg_returned,
:integer,
expr(^arg(:seconds)) do
argument(:seconds, :integer, allow_nil?: false)
public?(true)
end
end

relationships do
Expand Down
Loading