ash_graphql/lib/mix/tasks/ash_graphql.install.ex
Rebecca Le c3544dfe29
improvement: Set up GraphQL schema file in the web module namespace (#205)
This keeps consistency with AshJsonApi, which generates its router in the web module namespace as well
2024-08-03 09:49:55 -04:00

28 lines
973 B
Elixir

defmodule Mix.Tasks.AshGraphql.Install do
@moduledoc "Installs AshGraphql. Should be run with `mix igniter.install ash_postgres`"
@shortdoc @moduledoc
require Igniter.Code.Common
use Igniter.Mix.Task
def igniter(igniter, _argv) do
igniter =
igniter
|> Igniter.Project.Formatter.import_dep(:ash_graphql)
|> Spark.Igniter.prepend_to_section_order(:"Ash.Resource", [:graphql])
|> Spark.Igniter.prepend_to_section_order(:"Ash.Domain", [:graphql])
schema_name = Igniter.Libs.Phoenix.web_module_name("GraphqlSchema")
{igniter, candidate_ash_graphql_schemas} =
AshGraphql.Igniter.ash_graphql_schemas(igniter)
if Enum.empty?(candidate_ash_graphql_schemas) do
igniter
|> AshGraphql.Igniter.setup_absinthe_schema(schema_name)
|> AshGraphql.Igniter.setup_phoenix(schema_name)
else
igniter
|> Igniter.add_warning("AshGraphql schema already exists, skipping installation.")
end
end
end