ash_graphql/test/support/resources/post.ex

101 lines
2.2 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
list :paginated_posts, :paginated
2020-12-02 18:07:15 +13:00
end
managed_relationships do
managed_relationship :with_comments, :comments
end
2020-12-02 18:07:15 +13:00
mutations do
create :create_post, :create_confirm
create :upsert_post, :upsert, upsert?: true
create :create_post_with_comments, :with_comments
update :update_post, :update
update :update_best_post, :update, read_action: :best_post, identity: false
destroy :delete_post, :destroy
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
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
create :with_comments do
argument(:comments, {:array, :map})
change(manage_relationship(:comments, type: :direct_control))
end
read :paginated do
pagination(required?: true, offset?: true, countable: true)
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
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)
attribute(:published, :boolean, default: false)
attribute(:foo, AshGraphql.Test.Foo)
2021-03-29 08:46:23 +13:00
attribute(:status, AshGraphql.Test.Status)
attribute(:status_enum, AshGraphql.Test.StatusEnum)
attribute(:best, :boolean)
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)
has_many(:paginated_comments, AshGraphql.Test.Comment, read_action: :paginated)
end
2020-12-02 18:07:15 +13:00
end