【发布时间】:2019-11-26 20:18:45
【问题描述】:
使用 express 创建 Apollo 服务器时,http 和订阅端点默认为 /graphql。将 http 端点更改为 /graphql 以外的其他内容时,订阅端点始终指向 /graphql。如何使我的订阅端点与我的 http 端点相同?
这是来自 Apollo 网站的示例,我只添加了 path: custom_endpoint
const { ApolloServer } = require('apollo-server-express');
const express = require('express');
const PORT = 4000;
const app = express();
const server = new ApolloServer({ typeDefs, resolvers });
server.applyMiddleware({app, path: custom_endpoint})
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
// ⚠️ Pay attention to the fact that we are calling `listen` on the http server variable, and not on `app`.
httpServer.listen(PORT, () => {
console.log(`???? Server ready at http://localhost:${PORT}${server.graphqlPath}`) //this changes to my custom_endpoint
console.log(`???? Subscriptions ready at ws://localhost:${PORT}${server.subscriptionsPath}`) // this does not chnage to my custome_endpoint.```
【问题讨论】:
标签: express graphql apollo apollo-server