安装absinthe_plug后,出现以下错误:
= 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)
这是我的部门
{: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"},
据我所知,我不需要添加任何其他内容。我在这里遵循了简单的步骤:
absinthe_slug
编辑:我的路由器
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
我已经添加了要求Absinthe.Plug,但没有用
最佳答案
您正在将alias
(KerriganApiWeb
)传递给scope
,这会将别名附加到传递给内部路由声明函数的所有模块上。这会在对Absinthe.Plug
的调用中将KerriganApiWeb.Absinthe.Plug
转换为forward
,这不是您想要的。您需要模块Absinthe.Plug
。有两种解决方法:
删除alias
参数,并在所有需要它的路由声明函数中显式使用KerriganApiWeb
。
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
用相同的路径和管道创建一个新的
scope
,并在其中声明forward
路由: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
Phoenix文件say指出,第一个会增加应用程序的编译时间。即使不是这种情况,我也会选择第二种,因为我发现它更具可读性。
关于elixir - 苦艾插头,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45765950/