ash-project / ash

A declarative, extensible framework for building Elixir applications.
https://www.ash-hq.org
MIT License
1.63k stars 220 forks source link

Compile-time checks for code_interface arguments (both in Resource and Domain) #1520

Closed NduatiK closed 1 month ago

NduatiK commented 1 month ago

Is your feature request related to a problem? Please describe.

It can be pretty easy to get provide invalid argument or attribute names when defining a code_interface, especially after refactoring. This seems like something we might be able to check at compile time.

Example

defmodule MyResource do
  use Ash.Resource, ...

  resource do
    require_primary_key? false
  end

  code_interface do
    define :set, args: [:keys, :value] # <--- Should be :key, :value but no error is raised at compile time
  end

  actions do
    create :set do
      accept [:key, :value]
      ...
    end
  end

  attributes do
    attribute :key, :atom
    attribute :value, :integer
  end
end
defmodule MyDomain do
  use Ash.Domain

  resources do
    resource MyResource do
        define :set, args: [:keys, :value] # <--- Should be :key, :value but no error is raised at compile time
    end
end

Describe the solution you'd like

A compile-time error when these kind of mistakes are made, telling the user that the code interface will fail.

Bonus points if we can tell them "did you mean :key instead of :keys?"

NduatiK commented 1 month ago

PS. I can create a PR if you'd like. There are plenty of verifier examples available in the code.

zachdaniel commented 1 month ago

a PR would be wonderful 😄