当我测试我的graphql突变时,我遇到一个问题,它表明我确实传递了错误的参数
这是我要在graphiql中做的事情
mutation{
sendMessage(senderId:"sender" receiverId:"receiver" messageText:"some text in here"){
messageText
}
}
typeDefs
...
type Mutation{
....
sendMessage( senderId: String!, receiverId: String!, messageText: String! ): Message
}
resolvers.js
Mutation:{
sendMessage: async (root, { senderId, receiverId, messageText }, { User, Message }) => {
const newMessage = await new Message(senderId, receiverId, messageText).save();
return newMessage;
},
}
消息模型
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const MessageSchema = new Schema({
senderId: {
type: String,
required: true,
},
receiverId: {
type: String,
required: true
},
messageText: {
type: String,
required: true
}
});
module.exports = mongoose.model("Message", MessageSchema);
我希望成为some text in here
答案 0 :(得分:0)
问题是我没有传递物体;
sendMessage: async (root, { senderId, receiverId, messageText }, { User, Message }) => {
const newMessage = await new Message({senderId, receiverId, messageText}).save();
return newMessage;
},