mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-19 21:03:09 +12:00
fix: don't clear fields on nil
result
chore: add tests for destroy
This commit is contained in:
parent
89e6a314e3
commit
43dae2ad28
3 changed files with 47 additions and 2 deletions
|
@ -346,13 +346,14 @@ defmodule AshGraphql.Graphql.Resolver do
|
|||
}}
|
||||
end
|
||||
|
||||
defp clear_fields(nil, _, _), do: nil
|
||||
|
||||
defp clear_fields(result, resource, resolution) do
|
||||
resolution
|
||||
|> fields(true)
|
||||
|> Enum.map(fn field ->
|
||||
Ash.Resource.Info.aggregate(resource, field.schema_node.identifier) ||
|
||||
Ash.Resource.Info.calculation(resource, field.schema_node.identifier) ||
|
||||
Ash.Resource.Info.attribute(resource, field.schema_node.identifier)
|
||||
Ash.Resource.Info.calculation(resource, field.schema_node.identifier)
|
||||
end)
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.map(& &1.name)
|
||||
|
|
43
test/destroy_test.exs
Normal file
43
test/destroy_test.exs
Normal file
|
@ -0,0 +1,43 @@
|
|||
defmodule AshGraphql.DestroyTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
setup do
|
||||
on_exit(fn ->
|
||||
try do
|
||||
ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Post))
|
||||
ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Comment))
|
||||
rescue
|
||||
_ ->
|
||||
:ok
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
test "a destroy works" do
|
||||
post = AshGraphql.Test.Api.create!(Ash.Changeset.new(AshGraphql.Test.Post, text: "foobar"))
|
||||
|
||||
resp =
|
||||
"""
|
||||
mutation DeletePost($id: ID) {
|
||||
deletePost(id: $id) {
|
||||
result{
|
||||
text
|
||||
}
|
||||
errors{
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|> Absinthe.run(AshGraphql.Test.Schema,
|
||||
variables: %{
|
||||
"id" => post.id
|
||||
}
|
||||
)
|
||||
|
||||
assert {:ok, result} = resp
|
||||
|
||||
refute Map.has_key?(result, :errors)
|
||||
assert %{data: %{"deletePost" => %{"result" => %{"text" => "foobar"}}}} = result
|
||||
end
|
||||
end
|
|
@ -17,6 +17,7 @@ defmodule AshGraphql.Test.Post do
|
|||
create :create_post, :create_confirm
|
||||
create :upsert_post, :upsert, upsert?: true
|
||||
update :update_post, :update
|
||||
destroy :delete_post, :destroy
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue