看来我的服务器是根据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');
...我收到此控制台消息:
WebSocket 连接到“ws://localhost:8080/”失败:连接在收到握手响应之前关闭
我错过了什么?