gpt4 book ai didi

elixir - Absinthe.Plug 不可用

转载 作者:行者123 更新时间:2023-12-03 23:16:51 24 4
gpt4 key购买 nike

安装 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

我添加了 require Absinthe.Plug 但这不起作用

最佳答案

您正在传递 alias ( KerriganApiWeb ) 到 scope ,它将别名添加到传递给内部路由声明函数的所有模块。这将转换 Absinthe.PlugKerriganApiWeb.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 - Absinthe.Plug 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45765950/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com