安装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
我添加了要求Absinthe.Plug,但那不起作用
答案 0 :(得分:23)
您将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
路由:
<script>
function nDates(date){
var nFechas = false;
$.ajax({
type: "POST",
url: 'prueba.php',
data: {date},
async: false,
success: function(data) {
if (data == 1)
nFechas = true;
else
nFechas = false;
},
error: function() {
alert('Error occured');
}
});
return nFechas;
}
$( function() {
$.datepicker.setDefaults($.datepicker.regional["es"]);
$( "#datepicker" ).datepicker({
dateFormat: 'yy-mm-dd',
changeMonth:true,
changeYear:true,
yearRange: "2017:2018",
firstDay: 1,
minDate: 0,
beforeShowDay: function (date) {
var datesLimits = 20;
var day = date.getDay();
var dd = date.getDate();
var mm = date.getMonth()+1;
var yyyy = date.getFullYear();
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var date = yyyy+'-'+mm+'-'+dd;
if (day == 6 || day == 0 ) {
return [false, "somecssclass"]
} else {
if (nDates(date)){
return [true, "someothercssclass"]
} else {
return [false, "somecssclass"]
}
}},
monthNames: ['Enero', 'Febrero', 'Marzo',
'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'Septiembre',
'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun',
'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
dayNamesMin: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
closeText: 'Cerrar',
prevText: 'Anterior',
nextText: 'Siguiente',
currentText: 'Hoy',
});
});
</script>
Phoenix文档say第一个会增加应用程序的编译时间。即使不是这种情况,我也会选择第二个,因为我发现它更具可读性。
答案 1 :(得分:0)
您可以将两个端点“/ graph”和“graphiql”移出范围“/".
#AutoNumber15