And*_*dez 2 heroku apollo-server
所以我有一个使用 apollo-server-express 运行的 apollo-server:
const PORT = process.env.PORT || 8000
const graphqlPath = process.env.GRAPHQL || 'graphql'
const app = express()
app.use(cors())
app.use(bodyParser.text({ type: 'application/graphql' }))
const gqlServer = new ApolloServer({
typeDefs: schema,
resolvers,
context: {
me: users[1]
},
debug: true,
tracing: true
})
gqlServer.applyMiddleware({ app, path: `/${graphqlPath}` })
app.listen(PORT, () => console.log(`graphql listening on port ${PORT}`))
module.exports = app
Run Code Online (Sandbox Code Playgroud)
它在本地主机上完美运行,但是将其部署到heroku,当我运行操场时,它变得很奇怪:
以下是控制台错误的示例:
POST <graphql_server_url> 400(错误请求)
错误:响应不成功:收到状态代码 400
小智 6
尝试将内省和游乐场添加到 ApolloServer 配置中并设置为 true。当 Node 环境设置为生产环境时,它们会自动关闭,但这样您就可以在产品中启用它。参考: https: //www.apollographql.com/docs/apollo-server/v2/testing/graphql-playground/#enabling-graphql-playground-in-product
const gqlServer = new ApolloServer({
typeDefs: schema,
resolvers,
context: {
me: users[1]
},
debug: true,
tracing: true,
introspection: true,
playground: true
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1218 次 |
| 最近记录: |