ash_graphql/test/support/resources/user.ex

48 lines
839 B
Elixir
Raw Normal View History

2021-04-04 19:10:50 +12:00
defmodule AshGraphql.Test.User do
@moduledoc false
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
authorizers: [Ash.Policy.Authorizer],
2021-04-04 19:10:50 +12:00
extensions: [AshGraphql.Resource]
graphql do
type :user
queries do
read_one :current_user, :current_user, allow_nil?: false
2021-04-04 19:10:50 +12:00
end
mutations do
create :create_user, :create
# update :update_user, :update
end
2021-04-04 19:10:50 +12:00
end
actions do
defaults([:create, :update, :destroy, :read])
create(:create_policies)
2021-04-04 19:10:50 +12:00
read :current_user do
filter(id: actor(:id))
end
end
attributes do
uuid_primary_key(:id)
attribute(:name, :string)
end
policies do
policy action_type(:create) do
actor_attribute_equals(:name, "My Name")
end
policy action_type(:read) do
authorize_if(always())
end
end
2021-04-04 19:10:50 +12:00
end