mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-19 21:03:09 +12:00
fix: resolve testing compilation errors
This commit is contained in:
parent
22965dc05a
commit
e433b57eda
6 changed files with 51 additions and 36 deletions
|
@ -12,6 +12,9 @@ defmodule AshGraphql do
|
|||
api
|
||||
|> List.wrap()
|
||||
|> Kernel.++(List.wrap(apis))
|
||||
|
||||
apis =
|
||||
apis
|
||||
|> Enum.map(&{&1, false})
|
||||
|> List.update_at(0, fn {api, _} -> {api, true} end)
|
||||
|
||||
|
@ -20,6 +23,8 @@ defmodule AshGraphql do
|
|||
@moduledoc false
|
||||
alias Absinthe.{Blueprint, Phase, Pipeline}
|
||||
|
||||
Code.ensure_compiled(api)
|
||||
|
||||
def pipeline(pipeline) do
|
||||
Pipeline.insert_before(
|
||||
pipeline,
|
||||
|
@ -31,45 +36,40 @@ defmodule AshGraphql do
|
|||
def run(blueprint, _opts) do
|
||||
api = unquote(api)
|
||||
|
||||
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)
|
||||
Code.ensure_compiled(api)
|
||||
|
||||
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_queries =
|
||||
api
|
||||
|> AshGraphql.Api.queries(__MODULE__)
|
||||
|> Enum.reduce(blueprint, fn query, blueprint ->
|
||||
Absinthe.Blueprint.add_field(blueprint, "RootQueryType", query)
|
||||
end)
|
||||
|
||||
type_definitions =
|
||||
if unquote(first?) do
|
||||
AshGraphql.Api.global_type_definitions(__MODULE__) ++
|
||||
AshGraphql.Api.type_definitions(api, __MODULE__)
|
||||
else
|
||||
AshGraphql.Api.type_definitions(api, __MODULE__)
|
||||
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
|
||||
| imports: [{Absinthe.Type.Custom, []} | List.wrap(schema_def.imports)],
|
||||
type_definitions: schema_def.type_definitions ++ type_definitions
|
||||
}
|
||||
end)
|
||||
type_definitions =
|
||||
if unquote(first?) do
|
||||
AshGraphql.Api.global_type_definitions(__MODULE__) ++
|
||||
AshGraphql.Api.type_definitions(api, __MODULE__)
|
||||
else
|
||||
AshGraphql.Api.type_definitions(api, __MODULE__)
|
||||
end
|
||||
|
||||
{:ok, %{blueprint_with_mutations | schema_definitions: new_defs}}
|
||||
new_defs =
|
||||
List.update_at(blueprint_with_mutations.schema_definitions, 0, fn schema_def ->
|
||||
%{
|
||||
schema_def
|
||||
| imports: [{Absinthe.Type.Custom, []} | List.wrap(schema_def.imports)],
|
||||
type_definitions: schema_def.type_definitions ++ type_definitions
|
||||
}
|
||||
end)
|
||||
|
||||
{:error, _} ->
|
||||
# Something else will fail here, so we don't need to
|
||||
{:ok, blueprint}
|
||||
end
|
||||
{:ok, %{blueprint_with_mutations | schema_definitions: new_defs}}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
defmodule AshGraphql.CreateTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
setup do
|
||||
on_exit(fn ->
|
||||
nil
|
||||
# ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Post))
|
||||
end)
|
||||
end
|
||||
|
||||
test "a create with arguments works" do
|
||||
resp =
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
defmodule AshGraphql.Test.Api do
|
||||
@moduledoc false
|
||||
|
||||
use Ash.Api
|
||||
|
||||
resources do
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
defmodule AshGraphql.Test.Post do
|
||||
@moduledoc false
|
||||
|
||||
use Ash.Resource,
|
||||
data_layer: Ash.DataLayer.Ets,
|
||||
extensions: [AshGraphql.Resource]
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
defmodule AshGraphql.Test.Schema do
|
||||
@moduledoc false
|
||||
|
||||
use Absinthe.Schema
|
||||
|
||||
@apis [AshGraphql.Test.Api]
|
||||
|
@ -15,7 +17,7 @@ defmodule AshGraphql.Test.Schema do
|
|||
AshGraphql.add_context(ctx, @apis)
|
||||
end
|
||||
|
||||
def plugins() do
|
||||
def plugins do
|
||||
[Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
ExUnit.start()
|
||||
|
||||
Code.ensure_compiled(AshGraphql.Test.Api)
|
||||
|
|
Loading…
Reference in a new issue