【问题标题】:Absinthe middleware not applying/running on query苦艾酒中间件未在查询中应用/运行
【发布时间】:2021-12-15 15:20:12
【问题描述】:

我有 Absinthe 中间件,可以检查经过身份验证的用户的上下文,如下所示:

defmodule CliftonWeb.Middlewares.CheckAuth do
  @behaviour Absinthe.Middleware
  require Logger

  def call(resolution, _config) do
    case resolution.context do
      %{current_user: _} ->
        resolution
      _ ->
        resolution
        |> Absinthe.Resolution.put_result({:error, "unauthenticated"})
    end
  end
end

然后将其应用到我的架构中:

defmodule CliftonWeb.Schema do
  # Imports and plugin setup etc...


  def middleware(middleware, _field, %{identifier: :student_queries} = object) do
    [CliftonWeb.Middlewares.CheckAuth | middleware ]
  end

  def middleware(middleware, _field, object), do: middleware

  query do
    import_fields :student_queries
    # etc...
  end

end

但是,当我进行查询时,永远不会调用中间件。是否可以匹配任何标识符,或仅匹配 querymutation 等?

此外,这是仅将中间件应用于某些查询/突变组的最佳方式吗?

【问题讨论】:

    标签: elixir phoenix-framework absinthe


    【解决方案1】:

    无法匹配在 middleware/2 回调中使用 import_fields 导入的组。您可以查看在对象/字段上设置__private__ 标志,看看是否可以匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-08
      • 2018-01-16
      • 2020-05-04
      • 2018-03-19
      • 2018-12-25
      • 1970-01-01
      • 2018-12-14
      • 2021-08-20
      相关资源
      最近更新 更多