【发布时间】:2017-02-07 11:55:24
【问题描述】:
我的服务器似乎是根据http://dev.apollodata.com/tools/apollo-server/setup.html 的 Apollo 文档设置的。在我的 server/main.js 文件中:
//SET UP APOLLO INCLUDING APOLLO PUBSUB
const executableSchema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers,
connectors: Connectors,
logger: console,
});
const GRAPHQL_PORT = 8080;
const graphQLServer = express();
// `context` must be an object and can't be undefined when using connectors
graphQLServer.use('/graphql', bodyParser.json(), apolloExpress({
schema: executableSchema,
context: {}, //at least(!) an empty object
}));
graphQLServer.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql`
));
//SET UP APOLLO INCLUDING APOLLO PUBSUB
它在终端日志中打印出“GraphQL Server is now running on http://localhost:8080/graphql”,表明服务器已成功初始化。
但是在我的 main_layout 组件的顶部,当我运行这段代码时:
import { Client } from 'subscriptions-transport-ws';
const wsClient = new Client('ws://localhost:8080');
...我收到此控制台消息:
到 'ws://localhost:8080/' 的 WebSocket 连接失败:在收到握手响应之前连接已关闭
我错过了什么?
【问题讨论】:
标签: apollo apollo-server apollostack