Skip to content

Commit

Permalink
Fix compilation bug with persistent_term backend
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed committed Oct 21, 2020
1 parent d585bbb commit 5b4f198
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
13 changes: 13 additions & 0 deletions lib/absinthe/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ defmodule Absinthe.Schema do

@schema_provider Absinthe.Schema.Compiled

@on_load :__on_load__
def __on_load__ do
if __absinthe_schema_provider__() == Absinthe.Schema.PersistentTerm do
Absinthe.Phase.Schema.PopulatePersistentTerm.run(__absinthe_blueprint__(),
prototype_schema: __absinthe_prototype_schema__(),
schema: __MODULE__
)
end

:ok
end

def __absinthe_lookup__(name) do
__absinthe_type__(name)
end
Expand Down Expand Up @@ -140,6 +152,7 @@ defmodule Absinthe.Schema do
end
end

@deprecated "`Absinthe.Schema` process no longer needed, please remove it from your supervision tree."
def child_spec(schema) do
%{
id: {__MODULE__, schema},
Expand Down
21 changes: 2 additions & 19 deletions lib/absinthe/schema/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@ defmodule Absinthe.Schema.Manager do
GenServer.start_link(__MODULE__, schema, [])
end

def init(schema_module) do
prototype_schema = schema_module.__absinthe_prototype_schema__

pipeline =
schema_module
|> Absinthe.Pipeline.for_schema(prototype_schema: prototype_schema)
|> Absinthe.Schema.apply_modifiers(schema_module)

schema_module.__absinthe_blueprint__
|> Absinthe.Pipeline.run(pipeline)
|> case do
{:ok, _, _} ->
[]

{:error, errors, _} ->
raise Absinthe.Schema.Error, phase_errors: List.wrap(errors)
end

{:ok, schema_module}
def init(_schema_module) do
:ignore
end
end
17 changes: 2 additions & 15 deletions lib/absinthe/schema/persistent_term.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,13 @@ if Code.ensure_loaded?(:persistent_term) do
```
@schema_provider Absinthe.Schema.PersistentTerm
```
In your application's supervision tree, prior to anywhere where you'd use
the schema:
```
{Absinthe.Schema, MyAppWeb.Schema}
```
where MyAppWeb.Schema is the name of your schema.
"""

@behaviour Absinthe.Schema.Provider

def pipeline(pipeline) do
Enum.map(pipeline, fn
{Absinthe.Phase.Schema.Compile, options} ->
{Absinthe.Phase.Schema.PopulatePersistentTerm, options}

phase ->
phase
end)
pipeline
|> Absinthe.Pipeline.without(Absinthe.Phase.Schema.Compile)
end

def __absinthe_type__(schema_mod, name) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule Absinthe.Mixfile do
{:nimble_parsec, "~> 0.5"},
{:telemetry, "~> 0.4.0"},
{:dataloader, "~> 1.0.0", optional: true},
{:decimal, "~> 1.0 or ~> 2.0" , optional: true},
{:decimal, "~> 1.0 or ~> 2.0", optional: true},
{:ex_doc, "~> 0.21.0", only: :dev},
{:benchee, ">= 1.0.0", only: :dev},
{:dialyxir, "~> 1.0.0", only: [:dev, :test], runtime: false},
Expand Down

0 comments on commit 5b4f198

Please sign in to comment.