2024-01-25 08:59:12 +13:00
|
|
|
defmodule AshGraphql.Test.RelayIds.User do
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
use Ash.Resource,
|
|
|
|
data_layer: Ash.DataLayer.Ets,
|
|
|
|
extensions: [AshGraphql.Resource]
|
|
|
|
|
|
|
|
graphql do
|
|
|
|
type :user
|
|
|
|
|
|
|
|
queries do
|
|
|
|
get :get_user, :read
|
|
|
|
end
|
|
|
|
|
|
|
|
mutations do
|
|
|
|
create :create_user, :create
|
2024-02-07 03:46:09 +13:00
|
|
|
update :assign_posts, :assign_posts, relay_id_translations: [input: [post_ids: :post]]
|
2024-01-25 08:59:12 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
defaults([:create, :update, :destroy, :read])
|
2024-02-07 03:46:09 +13:00
|
|
|
|
|
|
|
update :assign_posts do
|
|
|
|
argument(:post_ids, {:array, :uuid})
|
|
|
|
|
|
|
|
change(manage_relationship(:post_ids, :posts, value_is_key: :id, type: :append_and_remove))
|
|
|
|
end
|
2024-01-25 08:59:12 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id)
|
|
|
|
attribute(:name, :string)
|
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
|
|
|
has_many(:posts, AshGraphql.Test.RelayIds.Post, destination_attribute: :author_id)
|
|
|
|
end
|
|
|
|
end
|