Skip to content

Commit dd8e210

Browse files
committed
add tests for using args in calculations for filters and sorts
1 parent fa7dc01 commit dd8e210

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

test/resource_test.exs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,29 @@ defmodule AshGraphql.ResourceTest do
187187

188188
assert List.first(data)["rank"] < List.last(data)["rank"]
189189
end
190+
191+
test "can use argument in filter and sort on calculated field" do
192+
[
193+
"a",
194+
"b",
195+
"c"
196+
]
197+
|> Enum.each(fn text ->
198+
Ash.Seed.seed!(%AshGraphql.Test.Comment{text: text})
199+
end)
200+
201+
assert {:ok, %{data: %{"listComments" => data}}} =
202+
"""
203+
query {
204+
listComments(
205+
filter: {timestampWithArg: {input: {seconds: 10}}}
206+
sort: {timestampWithArgInput: {seconds: 10}, field: TIMESTAMP_WITH_ARG, order: ASC_NULLS_LAST}
207+
) {
208+
text
209+
timestampWithArg(seconds: 10)
210+
}
211+
}
212+
"""
213+
|> Absinthe.run(AshGraphql.Test.Schema)
214+
end
190215
end

test/support/resources/comment.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ defmodule AshGraphql.Test.Comment do
7575
expr(created_at),
7676
public?: true
7777
)
78+
79+
calculate :timestamp_with_arg,
80+
:utc_datetime_usec,
81+
expr(created_at + fragment("make_interval(secs => ?)", ^arg(:seconds))) do
82+
argument(:seconds, :integer, allow_nil?: false)
83+
public?(true)
84+
end
7885
end
7986

8087
relationships do

0 commit comments

Comments
 (0)