小编Beh*_*adV的帖子

NestJS GraphQL 订阅不适用于“graphql-ws”

我正在尝试升级我们的 NestJS GraphQL 订阅服务器以利用graphql-ws而不是当前的subscriptions-transport-ws(如NestJS 文档所建议的)。我将NestJS版本升级到

    "@nestjs/core": "^8.0.6",
    "@nestjs/graphql": "^9.0.4",
    "@nestjs/platform-express": "^8.0.6",
    "graphql": "^15.5.3",
    "graphql-tools": "^8.2.0",
    "apollo-server-express": "^3.3.0",
Run Code Online (Sandbox Code Playgroud)

之后,我将subscriptions选项添加到App.Module

    GraphQLModule.forRoot({
      autoSchemaFile: true,
      sortSchema: true,
      playground: true,
      installSubscriptionHandlers: true,
      subscriptions: {
        'graphql-ws': true
      },
    }),
Run Code Online (Sandbox Code Playgroud)

但是,当我(在操场上)订阅以前有效的订阅时,我得到:

{
  "error": "Could not connect to websocket endpoint ws://localhost:8880/graphql. Please check if the endpoint url is correct."
}
Run Code Online (Sandbox Code Playgroud)

在控制台中我得到:

WebSocket protocol error occured. It was most likely caused due to an unsupported subprotocol "graphql-ws" requested by …
Run Code Online (Sandbox Code Playgroud)

graphql graphql-subscriptions nestjs

12
推荐指数
2
解决办法
9506
查看次数

标签 统计

graphql ×1

graphql-subscriptions ×1

nestjs ×1