【发布时间】:2019-03-15 23:14:42
【问题描述】:
在版本 1 中可以使用此功能,但整个服务器配置已更改。这就是我在将 bodyparser() 添加到 express 应用程序之后所拥有的,正如 Daniel 在 cmets 中所建议的那样:
const server = new ApolloServer({
typeDefs,
resolvers,
playground: {
settings: {
'editor.theme': 'light',
}
},
})
// Initialize the app
const app = express();
app.use(cors())
app.use(bodyParser.json())
server.applyMiddleware({
app
})
app.post('/calc', function(req, res){
const {body} = req;
console.log("HOWDYHOWDYHOWDY", body) // <== body is {}
res.setHeader('content-type', 'application/json')
calculate(body)
.then(result => res.send(result))
.catch(e => res.status(400).send({error: e.toString()}))
})
请求正文永远不会到达 app.post 处理程序,尽管处理程序被调用。不过,我看到它从浏览器中输出。有什么想法吗?
更新: Daniel 得到了正确答案,但我在使用的请求标头中遇到了另一个问题。一旦我解决了这个问题,邮政处理程序就会收到身体。
【问题讨论】:
标签: graphql apollo-server