diff --git a/lib/ash_graphql.ex b/lib/ash_graphql.ex index d6a0572..9020bcd 100644 --- a/lib/ash_graphql.ex +++ b/lib/ash_graphql.ex @@ -22,33 +22,39 @@ defmodule AshGraphql do def run(blueprint, _opts) do api = unquote(api) - Code.ensure_compiled(api) - blueprint_with_queries = - api - |> AshGraphql.Api.queries(__MODULE__) - |> Enum.reduce(blueprint, fn query, blueprint -> - Absinthe.Blueprint.add_field(blueprint, "RootQueryType", query) - end) + case Code.ensure_compiled(api) do + {:module, _} -> + blueprint_with_queries = + api + |> AshGraphql.Api.queries(__MODULE__) + |> Enum.reduce(blueprint, fn query, blueprint -> + Absinthe.Blueprint.add_field(blueprint, "RootQueryType", query) + end) - blueprint_with_mutations = - api - |> AshGraphql.Api.mutations(__MODULE__) - |> Enum.reduce(blueprint_with_queries, fn mutation, blueprint -> - Absinthe.Blueprint.add_field(blueprint, "RootMutationType", mutation) - end) + blueprint_with_mutations = + api + |> AshGraphql.Api.mutations(__MODULE__) + |> Enum.reduce(blueprint_with_queries, fn mutation, blueprint -> + Absinthe.Blueprint.add_field(blueprint, "RootMutationType", mutation) + end) - new_defs = - List.update_at(blueprint_with_mutations.schema_definitions, 0, fn schema_def -> - %{ - schema_def - | type_definitions: - schema_def.type_definitions ++ - AshGraphql.Api.type_definitions(api, __MODULE__) - } - end) + new_defs = + List.update_at(blueprint_with_mutations.schema_definitions, 0, fn schema_def -> + %{ + schema_def + | type_definitions: + schema_def.type_definitions ++ + AshGraphql.Api.type_definitions(api, __MODULE__) + } + end) - {:ok, %{blueprint_with_mutations | schema_definitions: new_defs}} + {:ok, %{blueprint_with_mutations | schema_definitions: new_defs}} + + {:error, _} -> + # Something else will fail here, so we don't need to + {:ok, blueprint} + end end end