mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 21:13:10 +12:00
87627993b8
In an effort to improve compile times in general, and remove unnecessary compile time dependencies, the code interface is not defined by default. It is also now possible to define the code interface directly in the resource module, via ```elixir code_interface do define_for ApiModule end ``` If you need to reenable the code interface, simply add the following to your api module: ```elixir resources do define_interfaces? true ... end ```
53 lines
973 B
Elixir
53 lines
973 B
Elixir
defmodule Ash.Test.CodeInterfaceTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: true
|
|
|
|
defmodule User do
|
|
@moduledoc false
|
|
use Ash.Resource, data_layer: Ash.DataLayer.Ets
|
|
|
|
ets do
|
|
private?(true)
|
|
end
|
|
|
|
code_interface do
|
|
define :get_user, action: :read, get?: true, args: [:id]
|
|
define :read_users, action: :read
|
|
end
|
|
|
|
actions do
|
|
read :read do
|
|
primary? true
|
|
end
|
|
|
|
read :by_id do
|
|
argument :id, :uuid, allow_nil?: false
|
|
|
|
filter expr(id == ^arg(:id))
|
|
end
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
attribute :first_name, :string
|
|
attribute :last_name, :string
|
|
end
|
|
end
|
|
|
|
defmodule Api do
|
|
@moduledoc false
|
|
use Ash.Api
|
|
|
|
resources do
|
|
define_interfaces?(true)
|
|
|
|
resource(User)
|
|
end
|
|
end
|
|
|
|
test "get! raises on not found" do
|
|
assert_raise Ash.Error.Query.NotFound, fn ->
|
|
Api.get_user!(Ash.UUID.generate())
|
|
end
|
|
end
|
|
end
|