【发布时间】:2018-09-17 11:57:43
【问题描述】:
我正在尝试添加一个突变以允许客户端将文档添加到 LineItem 架构。我在下面编写的代码允许我在使用 GraphiQL 对其进行测试时执行此操作,但我得到的响应为空。如何修复代码以使响应成为新文档?
addLineItem: {
type: LineItemType,
args: {
orderId: {type: new GraphQLNonNull(GraphQLID)},
productId: {type: new GraphQLNonNull(GraphQLID)},
quantity: {type: new GraphQLNonNull(GraphQLInt)}
},
resolve(parent, args) {
Product.findById(args.productId, (err, result) => {
let price = result.price;
let subtotal = price*args.quantity;
let lineitem = new LineItem({
orderId : args.orderId,
productId : args.productId,
quantity : args.quantity,
subtotal: subtotal
});
return lineitem.save();
}}
}
},
【问题讨论】:
标签: javascript node.js graphql