mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
improvement: Add float type (#20)
This commit is contained in:
parent
5a1df9f95a
commit
c530245295
3 changed files with 38 additions and 0 deletions
|
@ -2103,6 +2103,7 @@ defmodule AshGraphql.Resource do
|
||||||
defp do_field_type(Ash.Type.UtcDatetime, _, _), do: :naive_datetime
|
defp do_field_type(Ash.Type.UtcDatetime, _, _), do: :naive_datetime
|
||||||
defp do_field_type(Ash.Type.UtcDatetimeUsec, _, _), do: :naive_datetime
|
defp do_field_type(Ash.Type.UtcDatetimeUsec, _, _), do: :naive_datetime
|
||||||
defp do_field_type(Ash.Type.UUID, _, _), do: :string
|
defp do_field_type(Ash.Type.UUID, _, _), do: :string
|
||||||
|
defp do_field_type(Ash.Type.Float, _, _), do: :float
|
||||||
|
|
||||||
# sobelow_skip ["DOS.StringToAtom"]
|
# sobelow_skip ["DOS.StringToAtom"]
|
||||||
defp atom_enum_type(resource, attribute_name) do
|
defp atom_enum_type(resource, attribute_name) do
|
||||||
|
|
|
@ -14,6 +14,35 @@ defmodule AshGraphql.ReadTest do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "float fields works correctly" do
|
||||||
|
AshGraphql.Test.Post
|
||||||
|
|> Ash.Changeset.for_create(:create, text: "foo", published: true, score: 9.8)
|
||||||
|
|> AshGraphql.Test.Api.create!()
|
||||||
|
|
||||||
|
AshGraphql.Test.Post
|
||||||
|
|> Ash.Changeset.for_create(:create, text: "bar", published: true, score: 9.85)
|
||||||
|
|> AshGraphql.Test.Api.create!()
|
||||||
|
|
||||||
|
resp =
|
||||||
|
"""
|
||||||
|
query PostScore($score: Float) {
|
||||||
|
postScore(score: $score) {
|
||||||
|
text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|> Absinthe.run(AshGraphql.Test.Schema,
|
||||||
|
variables: %{
|
||||||
|
"score" => 9.8
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, result} = resp
|
||||||
|
|
||||||
|
refute Map.has_key?(result, :errors)
|
||||||
|
assert %{data: %{"postScore" => [%{"text" => "foo"}]}} = result
|
||||||
|
end
|
||||||
|
|
||||||
test "a read with arguments works" do
|
test "a read with arguments works" do
|
||||||
AshGraphql.Test.Post
|
AshGraphql.Test.Post
|
||||||
|> Ash.Changeset.for_create(:create, text: "foo", published: true)
|
|> Ash.Changeset.for_create(:create, text: "foo", published: true)
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule AshGraphql.Test.Post do
|
||||||
queries do
|
queries do
|
||||||
get :get_post, :read
|
get :get_post, :read
|
||||||
list :post_library, :library
|
list :post_library, :library
|
||||||
|
list :post_score, :score
|
||||||
list :paginated_posts, :paginated
|
list :paginated_posts, :paginated
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,6 +71,12 @@ defmodule AshGraphql.Test.Post do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
read :score do
|
||||||
|
argument(:score, :float, allow_nil?: true)
|
||||||
|
|
||||||
|
filter(expr(score == ^arg(:score)))
|
||||||
|
end
|
||||||
|
|
||||||
read :best_post do
|
read :best_post do
|
||||||
filter(expr(best == true))
|
filter(expr(best == true))
|
||||||
end
|
end
|
||||||
|
@ -87,6 +94,7 @@ defmodule AshGraphql.Test.Post do
|
||||||
attribute(:status, AshGraphql.Test.Status)
|
attribute(:status, AshGraphql.Test.Status)
|
||||||
attribute(:status_enum, AshGraphql.Test.StatusEnum)
|
attribute(:status_enum, AshGraphql.Test.StatusEnum)
|
||||||
attribute(:best, :boolean)
|
attribute(:best, :boolean)
|
||||||
|
attribute(:score, :float)
|
||||||
end
|
end
|
||||||
|
|
||||||
calculations do
|
calculations do
|
||||||
|
|
Loading…
Reference in a new issue