【问题标题】:Why my Absinthe GraphQL Subscription doesn't work?为什么我的 Absinthe GraphQL 订阅不起作用?
【发布时间】:2020-05-25 09:01:13
【问题描述】:

我的架构:

 subscription do
    @desc "Subscribe to drawing change"
    field :drawing_change, :drawing do
      # arg(:drawing_id, non_null(:id))

      config(fn _args, _resolution ->
        {:ok, topic: "*"}
      end)
    end
  end

当我这样做时

subscription {
  drawingChange {
    data
    name
  }
}

我收到此错误TypeError: Failed to fetch

日志:

[debug] Processing with Absinthe.Plug
  Parameters: %{"query" => "subscription {\n  drawingChange {\n    data\n    name\n  }\n}", "variables" => nil}
  Pipelines: [:api]
[debug] ABSINTHE schema=DrawingApiWeb.Schema.Schema variables=%{}
---
subscription {
  drawingChange {
    data
    name
  }
}
---
[info] Chunked 200 in 107ms

这是我的其余设置:

用户套接字: use Absinthe.Phoenix.Socket, schema: DrawingApiWeb.Schema.Schema

结束语: use Absinthe.Phoenix.Endpoint

路由器:

forward "/graphiql", Absinthe.Plug.GraphiQL,
      schema: DrawingApiWeb.Schema.Schema,
      socket: DrawingApiWeb.UserSocket

所有这一切都发生在我对任何上下文进行任何更改之前。无论问题是什么,它都应该在设置中。我已按照 Absinthe-GraphQL 书和 Pragmatic Studio 视频中的确切说明进行操作,并使用 https://hexdocs.pm/absinthe/subscriptions.html 进行了验证

还是同样的错误。 提前感谢您的帮助。

【问题讨论】:

    标签: graphql phoenix-channels absinthe absinthe-subscription


    【解决方案1】:

    我找到了。

    我没有在 Graphiql 中设置ws://localhost:4000/socket

    现在一切都好。 干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 2020-03-24
      • 2023-03-16
      • 2020-10-06
      • 2017-11-18
      相关资源
      最近更新 更多