2024-01-25 08:59:12 +13:00
|
|
|
defmodule AshGraphql.Test.RelayIds.Post do
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
use Ash.Resource,
|
2024-04-02 07:03:06 +13:00
|
|
|
domain: AshGraphql.Test.RelayIds.Domain,
|
2024-01-25 08:59:12 +13:00
|
|
|
data_layer: Ash.DataLayer.Ets,
|
|
|
|
extensions: [AshGraphql.Resource]
|
|
|
|
|
|
|
|
require Ash.Query
|
|
|
|
|
|
|
|
graphql do
|
|
|
|
type :post
|
|
|
|
|
|
|
|
queries do
|
|
|
|
get :get_post, :read
|
|
|
|
list :post_library, :read
|
|
|
|
end
|
|
|
|
|
|
|
|
mutations do
|
2024-02-07 03:46:09 +13:00
|
|
|
create :simple_create_post, :create, relay_id_translations: [input: [author_id: :user]]
|
2024-01-25 08:59:12 +13:00
|
|
|
update :update_post, :update
|
2024-02-07 03:46:09 +13:00
|
|
|
update :assign_author, :assign_author, relay_id_translations: [input: [author_id: :user]]
|
2024-01-25 08:59:12 +13:00
|
|
|
destroy :delete_post, :destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
2024-04-02 07:03:06 +13:00
|
|
|
default_accept(:*)
|
2024-01-25 08:59:12 +13:00
|
|
|
defaults([:update, :read, :destroy])
|
|
|
|
|
|
|
|
create :create do
|
|
|
|
primary?(true)
|
|
|
|
argument(:author_id, :uuid)
|
|
|
|
|
|
|
|
change(set_attribute(:author_id, arg(:author_id)))
|
|
|
|
end
|
2024-02-07 03:46:09 +13:00
|
|
|
|
|
|
|
update :assign_author do
|
|
|
|
argument(:author_id, :uuid)
|
|
|
|
|
|
|
|
change(set_attribute(:author_id, arg(:author_id)))
|
|
|
|
end
|
2024-01-25 08:59:12 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id)
|
2024-04-02 07:03:06 +13:00
|
|
|
attribute(:text, :string, public?: true)
|
2024-01-25 08:59:12 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
|
|
|
belongs_to(:author, AshGraphql.Test.RelayIds.User) do
|
2024-04-02 07:03:06 +13:00
|
|
|
public?(true)
|
2024-01-25 08:59:12 +13:00
|
|
|
attribute_writable?(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|