After installing absinthe_plug I'm getting the following error:
= Compilation error in file lib/kerrigan_api_web/router.ex ==
** (UndefinedFunctionError) function KerriganApiWeb.Absinthe.Plug.init/1 is undefined (module KerriganApiWeb.Absinthe.Plug is not available)
Here are my deps
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.2"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.10"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:poison, "~> 3.1"},
{:absinthe, "~> 1.3.0"},
{:absinthe_plug, "~> 1.3.0"},
{:absinthe_ecto, git: "https://github.com/absinthe-graphql/absinthe_ecto.git"},
{:faker, "~> 0.7"},
As far as I'm aware I dont need to add anything else. I've followed the simple steps here:
absinthe_slug
EDIT: My router
defmodule KerriganApiWeb.Router do
use KerriganApiWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", KerriganApiWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
resources "/hotsdata_user", UserController, except: [:new, :edit]
resources "/battletag_toonhandle_lookup", PlayerController, except: [:new, :edit]
forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema
forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema
end
end
I had added require Absinthe.Plug but that didn't work
You're passing an alias
(KerriganApiWeb
) to scope
, which prepends the alias to all modules passed to the route declaration functions inside. This converts Absinthe.Plug
to KerriganApiWeb.Absinthe.Plug
in the call to forward
, which is not what you want. You want the module Absinthe.Plug
. There are two ways to solve this:
Remove alias
parameter and use KerriganApiWeb
explicitly in all route declaration functions that need it.
scope "/" do
pipe_through :browser # Use the default browser stack
get "/", KerriganApiWeb.PageController, :index
resources "/hotsdata_user", KerriganApiWeb.UserController, except: [:new, :edit]
resources "/battletag_toonhandle_lookup", KerriganApiWeb.PlayerController, except: [:new, :edit]
forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema
forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema
end
Create a new scope
with the same path and pipeline and declare the forward
routes there:
scope "/", KerriganApiWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
resources "/hotsdata_user", UserController, except: [:new, :edit]
resources "/battletag_toonhandle_lookup", PlayerController, except: [:new, :edit]
end
scope "/" do
forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema
forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema
end
The Phoenix docs say that the first one will increase the compilation time of your application. Even if that weren't the case I'd go with the second one as I find that more readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With