【发布时间】:2018-06-01 02:51:52
【问题描述】:
我基本上创建了快递服务器,然后添加了订阅服务器。
/*
* 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 链接会非常有帮助:)
非常感谢
【问题讨论】:
标签: express graphql apollo subscriptions