我基本上创建了一个Express服务器,然后添加了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
`)
})
当我尝试连接GraphQLi订阅服务器时,它抛出了一个错误。
WebSocket connection to 'ws://localhost:10005/subscriptions' failed: Connection closed before receiving a handshake response
我不知道这意味着什么,也不知道问题出在哪里。
如果有人做过类似的项目,可以给我发送GitHub链接,那将非常有帮助:)
非常感谢