小编Ver*_*ido的帖子

如何解决GraphQL订阅服务器中的WebSocket错误

我基本上创建了快速服务器,然后添加了SubscriptionServer。

/*
*   GRAPHQL SERVER
*/

const graphqlServer = express()
graphqlServer.use(cors())
graphqlServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema: schema }))
graphqlServer.get('/graphiql', graphiqlExpress({ endpointURL: '/graphql', subscriptionsEndpoint: `ws://localhost:${process.env.GRAPHQL_PORT}/subscriptions`, }))

graphqlServer.listen(process.env.GRAPHQL_PORT, () => {

  SubscriptionServer.create(
    {
      schema,
      execute,
      subscribe,
    },
    {
      server: graphqlServer,
      path: '/subscriptions',
    },
  )

  console.log(`
    - GraphQL server listening on http://localhost:${process.env.GRAPHQL_PORT}
    - GraphQL subscriptions listening on ws://localhost:${process.env.GRAPHQL_PORT}/subscriptions
    `)
})
Run Code Online (Sandbox Code Playgroud)

比当我尝试在GraphQLi订阅服务器上进行连接时,它引发了错误。

WebSocket connection to 'ws://localhost:10005/subscriptions' failed: Connection closed before receiving a handshake response
Run Code Online (Sandbox Code Playgroud)

我不知道这意味着什么,也不知道问题在哪里。

如果有人做过类似的项目,给我发github链接可能会很有帮助:)

非常感谢

subscriptions express apollo graphql

5
推荐指数
1
解决办法
577
查看次数

标签 统计

apollo ×1

express ×1

graphql ×1

subscriptions ×1