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
|
2021-05-05 01:31:39 +12:00
|
|
|
list :paginated_posts, :paginated
|
2020-12-02 18:07:15 +13:00
|
|
|
end
|
|
|
|
|
2021-04-24 10:44:56 +12:00
|
|
|
managed_relationships do
|
|
|
|
managed_relationship :with_comments, :comments
|
|
|
|
end
|
|
|
|
|
2020-12-02 18:07:15 +13:00
|
|
|
mutations do
|
|
|
|
create :create_post, :create_confirm
|
2021-04-06 06:41:16 +12:00
|
|
|
create :upsert_post, :upsert, upsert?: true
|
2021-04-24 10:44:56 +12:00
|
|
|
|
|
|
|
create :create_post_with_comments, :with_comments
|
|
|
|
|
2021-03-16 08:51:17 +13:00
|
|
|
update :update_post, :update
|
2021-04-20 07:26:20 +12:00
|
|
|
update :update_best_post, :update, read_action: :best_post, identity: false
|
|
|
|
|
2021-04-17 04:55:34 +12:00
|
|
|
destroy :delete_post, :destroy
|
2021-04-20 07:26:20 +12:00
|
|
|
destroy :delete_best_post, :destroy, read_action: :best_post, identity: false
|
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
|
|
|
|
|
2021-04-24 10:44:56 +12:00
|
|
|
create :with_comments do
|
|
|
|
argument(:comments, {:array, :map})
|
|
|
|
|
|
|
|
change(manage_relationship(:comments, type: :direct_control))
|
|
|
|
end
|
|
|
|
|
2021-05-05 01:31:39 +12:00
|
|
|
read :paginated do
|
|
|
|
pagination(required?: true, offset?: true, countable: true)
|
|
|
|
end
|
|
|
|
|
2021-01-22 17:06:06 +13:00
|
|
|
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
|
|
|
|
|
2021-04-20 07:26:20 +12:00
|
|
|
read :best_post do
|
|
|
|
filter(expr(best == true))
|
|
|
|
end
|
|
|
|
|
2020-12-02 18:07:15 +13:00
|
|
|
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)
|
2021-04-24 10:44:56 +12:00
|
|
|
attribute(:status_enum, AshGraphql.Test.StatusEnum)
|
2021-04-20 07:26:20 +12:00
|
|
|
attribute(:best, :boolean)
|
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)
|
2021-05-05 01:31:39 +12:00
|
|
|
has_many(:paginated_comments, AshGraphql.Test.Comment, read_action: :paginated)
|
2021-03-16 08:51:17 +13:00
|
|
|
end
|
2020-12-02 18:07:15 +13:00
|
|
|
end
|