2020-12-02 18:07:15 +13:00
|
|
|
defmodule AshGraphql.Test.Post do
|
2020-12-02 18:55:25 +13:00
|
|
|
@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
|
2021-04-06 06:41:16 +12:00
|
|
|
create :upsert_post, :upsert, upsert?: true
|
2021-03-16 08:51:17 +13:00
|
|
|
update :update_post, :update
|
2020-12-02 18:07:15 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
create :create do
|
|
|
|
primary?(true)
|
|
|
|
end
|
|
|
|
|
2021-04-06 06:41:16 +12:00
|
|
|
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)
|
2021-01-22 17:06:06 +13:00
|
|
|
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)
|
2021-01-22 17:06:06 +13:00
|
|
|
attribute(:published, :boolean, default: false)
|
2021-03-29 05:30:28 +13:00
|
|
|
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
|
2021-03-16 08:51:17 +13:00
|
|
|
|
2021-03-23 06:03:18 +13:00
|
|
|
calculations do
|
|
|
|
calculate(:static_calculation, :string, AshGraphql.Test.StaticCalculation)
|
|
|
|
end
|
|
|
|
|
2021-03-16 08:51:17 +13:00
|
|
|
relationships do
|
|
|
|
has_many(:comments, AshGraphql.Test.Comment)
|
|
|
|
end
|
2020-12-02 18:07:15 +13:00
|
|
|
end
|