mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
fix: don't add graphql types if API doesn't compile
This commit is contained in:
parent
f81f8d45cb
commit
a7e4b165e4
1 changed files with 29 additions and 23 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue