拨号器(通过 Dialyxir)从 Absinthe (GraphQL) 路由的 `forward` 命令发出有关“但此值不匹配”的警告。如何解决?
Posted
技术标签:
【中文标题】拨号器(通过 Dialyxir)从 Absinthe (GraphQL) 路由的 `forward` 命令发出有关“但此值不匹配”的警告。如何解决?【英文标题】:Dializer (via Dialyxir) warning about "but this value is unmatched" from `forward` command for Absinthe (GraphQL) route. How to address? 【发布时间】:2020-04-16 13:24:42 【问题描述】:我收到关于不匹配返回的透析器错误,我不确定如何正确解决。
mix dialyzer --quiet
lib/my_app_web/router.ex:1:no_return
Function __checks__/0 has no local return.
________________________________________________________________________________
lib/my_app_web/router.ex:21:unmatched_return
The expression produces a value of type:
%
:adapter => _,
:before_send => _,
:content_type => _,
:context => _,
:document_providers => _,
:json_codec => _,
:log_level => _,
:no_query_message => _,
:pipeline => _,
:pubsub => _,
:raw_options => Keyword.t(),
:schema_mod => atom(),
:serializer => _
but this value is unmatched.
________________________________________________________________________________
lib/my_app_web/router.ex:24:unmatched_return
The expression produces a value of type:
%
:adapter => _,
:additional_pipeline => _,
:assets => _,
:before_send => _,
:content_type => _,
:context => _,
:default_headers => _,
:default_url => _,
:document_providers => _,
:interface => _,
:json_codec => _,
:log_level => _,
:no_query_message => _,
:pipeline => Absinthe.Plug.GraphiQL, :pipeline,
:pubsub => _,
:raw_options => [_, _],
:schema_mod => atom(),
:serializer => _,
:socket => _,
:socket_url => _
but this value is unmatched.
我的mix.exs
看起来像这样:
def project do
[
app: :my_app,
version: "0.1.0",
elixir: "1.9.4",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
dialyzer: [
plt_add_deps: :transitive,
flags: [:error_handling, :race_conditions, :unmatched_returns, :underspecs]
],
aliases: aliases(),
deps: deps()
]
end
我的router.ex
看起来像这样:
defmodule MyAppWeb.Router do
use MyAppWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug MyAppWeb.Auth
end
pipeline :api do
plug :accepts, ["json"]
end
# Other scopes may use custom stacks.
scope "/api" do
pipe_through :api
forward "/graphql", Absinthe.Plug, schema: MyAppWeb.Schema.UserTypes
if Mix.env() == :dev do
forward "/graphiql", Absinthe.Plug.GraphiQL,
schema: MyAppWeb.Schema.UserTypes,
interface: :simple
end
end
scope "/", MyAppWeb do
pipe_through :browser
resources "/users", UserController,
only: [:index, :show, :new, :create, :edit, :delete, :update]
resources "/sessions", SessionController, only: [:new, :create, :delete]
get "/", PageController, :index, as: :home
get "/*path", PageController, :index
end
end
我尝试了_ =
技巧,但它似乎不起作用。我认为使用无与伦比的回报可能会有所帮助,但在这种情况下可能不会。我已阅读此页面 (https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart),但我认为它无助于解决此问题。
任何反馈或指导将不胜感激。
谢谢
【问题讨论】:
请将整个router.ex
发帖,以便我们检查dialyzer 提到的第1、21、24 行。
@AlekseiMatiushkin 我添加了整个路由器。第 21 和 24 行或 graphql
和 graphiql
行。
也就是说,dialyzer 不喜欢forward
s。我从来没有用过 Absinth,但我会去检查他们的代码。
【参考方案1】:
我发现问题来自这个凤凰提交:https://github.com/phoenixframework/phoenix/commit/b10fb7dc33a198595872b783cbbf90f1daee91ba
可能是 Phoenix 问题或 Absinthe.Plug.init/1
规范导致警告。
在解决时间问题时,您可以使用 Dialyxir 的忽略警告功能:https://github.com/jeremyjh/dialyxir#ignore-warnings
【讨论】:
以上是关于拨号器(通过 Dialyxir)从 Absinthe (GraphQL) 路由的 `forward` 命令发出有关“但此值不匹配”的警告。如何解决?的主要内容,如果未能解决你的问题,请参考以下文章