首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Absinthe.Plug不可用

Absinthe.Plug不可用
EN

Stack Overflow用户
提问于 2017-08-18 22:45:12
回答 2查看 3.7K关注 0票数 17

安装absinthe_plug后,我将得到以下错误:

代码语言:javascript
复制
= 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)

这是我的助手

代码语言:javascript
复制
{: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"},

据我所知,我不需要再添加任何东西。我在这里遵循了简单的步骤:

弹状物

编辑:我的路由器

代码语言:javascript
复制
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,但这不起作用

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-18 23:12:01

您正在将一个alias (KerriganApiWeb)传递给scope,它为传递给内部路由声明函数的所有模块提供别名。这将在对Absinthe.Plug的调用中将forward转换为KerriganApiWeb.Absinthe.Plug,这不是您想要的。您需要模块Absinthe.Plug。解决这一问题的方法有两种:

  1. 删除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 end
  2. 使用相同的路径和管道创建一个新的scope,并在那里声明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

菲尼克斯文档第一个将增加您的应用程序的编译时间。即使不是这样,我也会选择第二个,因为我发现它更容易读懂。

票数 39
EN

Stack Overflow用户

发布于 2017-08-19 03:24:32

您只需将两个端点"/graph“和"graphiql”移出范围"/“即可。

代码语言:javascript
复制
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

end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45765950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档