ash-project / spark

Tooling for building DSLs in Elixir
MIT License
104 stars 23 forks source link

Add Spark.Dsl.Patch.ReplaceEntity, DeleteEntity #83

Closed jechol closed 3 months ago

jechol commented 3 months ago

Is your feature request related to a problem? Please describe. When creating an entity to replace Ash's default entity, there is no way to remove the existing entity.

Describe the solution you'd like Add Spark.Dsl.Patch.ReplaceEntity, DeleteEntity

Express the feature either with a change to resource syntax, or with a change to the resource interface

Instead of code with existing entity from Ash like below,

actions do
  create :insert do
    argument :foo, :integer, allow_nil?: true
    argument :bar, :integer, allow_nil?: false
  end
end

I want to write like this in my application.

actions do
  create :insert do
    opt :foo, :integer
    req :bar, :integer
  end
end

But there is no way to replace create entity with my custom create entity. I can only add a new entity but it makes call create ambiguous.

zachdaniel commented 3 months ago

I think for your specific example, there are two ways it could be approached.

  1. we could alter spark to make AddEntity allow adding entities to entities. argument is a nested entity within the create entity.

  2. you could define a macro

defmacro opt(name, type, opts) do
  quote do
    attribute unquote(name), unquote(type), unquote(Keyword.put(opts, :allow_nil?, true))
  end
end
zachdaniel commented 3 months ago

I'm going to close this particular issue, because allowing extensions to overwrite entities by other extensions is a whole can of worms that we should avoid unless we have no other option :)