安装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"},据我所知,我不需要再添加任何东西。我在这里遵循了简单的步骤:
编辑:我的路由器
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我添加了require Absinthe.Plug,但这不起作用
发布于 2017-08-18 23:12:01
您正在将一个alias (KerriganApiWeb)传递给scope,它为传递给内部路由声明函数的所有模块提供别名。这将在对Absinthe.Plug的调用中将forward转换为KerriganApiWeb.Absinthe.Plug,这不是您想要的。您需要模块Absinthe.Plug。解决这一问题的方法有两种:
alias参数,并在所有需要它的路由声明函数中显式使用KerriganApiWeb。
范围"/“do pipe_through :browser #使用默认的浏览器堆栈get "/",KerriganApiWeb.PageController,:索引资源"/hotsdata_user",KerriganApiWeb.UserController,除::new,:编辑资源"/battletag_toonhandle_lookup",KerriganApiWeb.PlayerController,除:new,:edit "/graph",Absinthe.Plug,schema: KerriganApi.Schema forward "/graphiql",Absinthe.Plug.GraphiQL,schema: KerriganApi.Schema endscope,并在那里声明forward路由:
范围"/",KerriganApiWeb do pipe_through :browser #使用默认的浏览器堆栈get "/",PageController,:索引资源"/hotsdata_user",UserController,除::new,:编辑资源"/battletag_toonhandle_lookup",PlayerController,除::new,:Use scope“/ do forward”/graph,Absinthe.Plug,schema: KerriganApi.Schema forward "/graphiql",Absinthe.Plug.GraphiQL,schema: KerriganApi.Schema end菲尼克斯文档说第一个将增加您的应用程序的编译时间。即使不是这样,我也会选择第二个,因为我发现它更容易读懂。
发布于 2017-08-19 03:24:32
您只需将两个端点"/graph“和"graphiql”移出范围"/“即可。
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]
end
forward "/graph", Absinthe.Plug, schema: KerriganApi.Schema
forward "/graphiql", Absinthe.Plug.GraphiQL, schema: KerriganApi.Schema, interface: :advanced
endhttps://stackoverflow.com/questions/45765950
复制相似问题