ash_graphql/test/support/resources/post.ex

72 lines
1.3 KiB
Elixir
Raw Normal View History

2020-12-02 18:07:15 +13:00
defmodule AshGraphql.Test.Post do
@moduledoc false
2020-12-02 18:07:15 +13:00
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
extensions: [AshGraphql.Resource]
graphql do
type :post
queries do
2021-04-04 19:10:50 +12:00
get :get_post, :read
list :post_library, :library
2020-12-02 18:07:15 +13:00
end
mutations do
create :create_post, :create_confirm
create :upsert_post, :upsert, upsert?: true
update :update_post, :update
2020-12-02 18:07:15 +13:00
end
end
actions do
create :create do
primary?(true)
end
create :upsert do
argument(:id, :uuid)
change(AshGraphql.Test.ForceChangeId)
end
2020-12-02 18:07:15 +13:00
create :create_confirm do
argument(:confirmation, :string)
validate(confirm(:text, :confirmation))
end
read(:read, primary?: true)
read :library do
argument(:published, :boolean, default: true)
filter(
expr do
published == ^arg(:published)
end
)
2020-12-02 18:07:15 +13:00
end
update(:update)
destroy(:destroy)
end
attributes do
uuid_primary_key(:id)
attribute(:text, :string)
attribute(:published, :boolean, default: false)
attribute(:foo, AshGraphql.Test.Foo)
2021-03-29 08:46:23 +13:00
attribute(:status, AshGraphql.Test.Status)
2020-12-02 18:07:15 +13:00
end
calculations do
calculate(:static_calculation, :string, AshGraphql.Test.StaticCalculation)
end
relationships do
has_many(:comments, AshGraphql.Test.Comment)
end
2020-12-02 18:07:15 +13:00
end