Aza*_* S. 4 apollo graphql apollo-server
有什么方法可以更改 Apollo Server WS 的路径(server.subscriptionsPath)?
默认路径是“/graphql”。如何设置其他路由,例如“ws://localhost:3000/api”?
import express from 'express'
import http from 'http'
import { ApolloServer } from 'apollo-server-express'
const app = express()
// ...
const server = new ApolloServer({
typeDefs,
resolvers,
})
const httpServer = http.createServer(app)
server.installSubscriptionHandlers(httpServer)
console.log('server.graphqlPath', server.graphqlPath)
console.log('server.subscriptionsPath', server.subscriptionsPath)
httpServer.listen({ port:300 })
Run Code Online (Sandbox Code Playgroud)
如果其他人正在寻找答案。这对我有用:
// ...
const server = new ApolloServer({
typeDefs,
resolvers,
})
// This is missing in your example
server.applyMiddleware({
app,
path: '/my-custom-path-here',
});
// ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3195 次 |
| 最近记录: |