Skip to content

Commit

Permalink
Staging a new test to help demonstrate an unexpected issue I am seein…
Browse files Browse the repository at this point in the history
…g in the `arguments` field of `Ash.Query`.
  • Loading branch information
zorn committed Aug 15, 2023
1 parent 8f9e79e commit 995e169
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/read_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,57 @@ defmodule AshGraphql.ReadTest do
assert %{data: %{"postLibrary" => [%{"text" => "foo"}]}} = result
end

test "a list read action returns expected list if argument is present (nil or actual value) or not present" do
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create, score: 1.23, published: true)
|> AshGraphql.Test.Api.create!()

AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create, score: nil, published: true)
|> AshGraphql.Test.Api.create!()

specific_score_query =
"""
query PostScore($score: Float) {
postScore(score: $score) {
id
score
}
}
"""

Absinthe.run(specific_score_query, AshGraphql.Test.Schema,
variables: %{
"score" => 1.23
}
)
|> dbg()

# TODO: assert you get a list of just the one post with `1.23` score.

Absinthe.run(specific_score_query, AshGraphql.Test.Schema,
variables: %{
"score" => nil
}
)
|> dbg()

# TODO: assert you get a list of just the one post with `nil` score.

"""
query {
postScore {
id
score
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema)
|> dbg()

# TODO: assert you see all the posts, no matter the score
end

test "a read with custom set types works" do
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create,
Expand Down
22 changes: 22 additions & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ defmodule AshGraphql.Test.Post do
read :score do
argument(:score, :float, allow_nil?: true)

# To help demonstrate the issue I am seeing,
# I recommend running my WIP test with:
#
# $ mix test.watch test/read_test.exs:227
#
# In the below `prepare` block I am debug printing the query. In the last
# of the three test queries there is no argument on the graph side of the
# relationship yet the `arguments` will sill show `%{score: nil}`. This
# make it difficult to utilize the argument as a filter both allowing
# users to list value that are `nil` while at the same time returning a
# full list when no arguments are passed in.
#
# query #=> #Ash.Query<
# resource: AshGraphql.Test.Post,
# arguments: %{score: nil},
# select: [:score, :id]
# >

prepare(fn query, _ ->
dbg(query)
end)

filter(expr(score == ^arg(:score)))
end

Expand Down

0 comments on commit 995e169

Please sign in to comment.