diff --git a/.formatter.exs b/.formatter.exs index 53a50b6c..808a5684 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -183,6 +183,7 @@ locals_without_parens = [ validate_destination_field?: 1, violation_message: 1, wait_for: 1, + warn_on_empty?: 1, where: 1, writable?: 1 ] diff --git a/lib/ash/registry/registry.ex b/lib/ash/registry/registry.ex index 23df4093..231a40b2 100644 --- a/lib/ash/registry/registry.ex +++ b/lib/ash/registry/registry.ex @@ -36,6 +36,11 @@ defmodule Ash.Registry do end end + @spec warn_on_empty?(t()) :: boolean + def warn_on_empty?(registry) do + Extension.get_opt(registry, [:entries], :warn_on_empty?, true, true) + end + @spec api_or_api_and_registry(Ash.Api.t() | {Ash.Api.t(), t()}) :: {t(), t()} def api_or_api_and_registry({api, registry}), do: {api, registry} def api_or_api_and_registry(api), do: {api, api} diff --git a/lib/ash/registry/transformers/warn_on_empty.ex b/lib/ash/registry/transformers/warn_on_empty.ex index a1180450..90a271eb 100644 --- a/lib/ash/registry/transformers/warn_on_empty.ex +++ b/lib/ash/registry/transformers/warn_on_empty.ex @@ -3,12 +3,16 @@ defmodule Ash.Registry.Transformers.WarnOnEmpty do use Ash.Dsl.Transformer def transform(registry, dsl) do - case Ash.Registry.entries(registry) do - [] -> - {:warn, dsl, "#{inspect(registry)} has no entries."} + if Ash.Registry.warn_on_empty?(registry) do + case Ash.Registry.entries(registry) do + [] -> + {:warn, dsl, "#{inspect(registry)} has no entries."} - _ -> - {:ok, dsl} + _ -> + {:ok, dsl} + end + else + {:ok, dsl} end end end