我正在尝试升级我们的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",之后,我将subscriptions选项添加到App.Module中
GraphQLModule.forRoot({
autoSchemaFile: true,
sortSchema: true,
playground: true,
installSubscriptionHandlers: true,
subscriptions: {
'graphql-ws': true
},
}),但是,当我(在操场上)订阅以前工作过的订阅时,我得到:
{
"error": "Could not connect to websocket endpoint ws://localhost:8880/graphql. Please check if the endpoint url is correct."
}在控制台里我得到:
WebSocket protocol error occured. It was most likely caused due to an unsupported subprotocol "graphql-ws" requested by the client. graphql-ws implements exclusively the "graphql-transport-ws" subprotocol, please make sure that the client implements it too.我尝试过的事情:
graphql-ws包installSubscriptionHandlers选项graphql-ws信任而不是传递trueWebSocket Test Client Google扩展而不是游乐场但都没有奏效。很抱歉寄了这么长的邮筒。我怎么才能解决这个问题?
发布于 2021-09-16 13:35:10
发布于 2022-02-21 12:01:59
这将完成以下工作:
subscriptions: {
'graphql-ws': true,
'subscriptions-transport-ws': true,
},正如在文档中提到的
提示 您还可以>同时使用两个包(订阅-transport和graphql),例如,为了实现向后兼容性。
https://stackoverflow.com/questions/69178586
复制相似问题