{@thread.name}

zachdaniel
2023-04-05

zachdaniel:

Many users have had issues with their resources getting too big. To alleviate this and allow for users to split up their resources while retaining the QoL features around Spark DSLs and not needing to write macros, we’ve released Spark.Dsl.Fragment . Since an example is worth a thousand words, here is what it could look like:

# configure the entire graphql section somewhere else
defmodule MyApp.Api.Resource.Graphql do
  use Spark.Dsl.Fragment, of: Ash.Resource, extensions: [AshGraphql.Resource]

  graphql do
    ...
  end
end

defmodule MyApp.Api.Resource.Actions.BigCrazyAction do
  use Spark.Dsl.Fragment, of: Ash.Resource

  actions do
    action :big_crazy_action do
      ...bunch of arguments
      manual ...
    end
  end
end

And then to use it

defmodule MyApp.Api.Resource do
  use Ash.Resource, fragments: [
    MyApp.Api.Resource.Graphql,
    MyApp.Api.Resource.Actions.BigCrazyAction
  ]
end