如何确定“猫鼬模型的名称"?变异时,它不是graphql中的构造函数 [英] How to fix the "Name of the mongoose Model" is not a constructor in graphql when mutating
本文介绍了如何确定“猫鼬模型的名称"?变异时,它不是graphql中的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在graphql游乐场中交换数据时会显示以下消息: 消息:学生不是构造函数 错误:"TypeError:学生不是构造函数" 学生是我的猫鼬模特.
Mutating data in the graphql playground says the message of Message: Student is not a constructor Error: "TypeError: Student is not a constructor" Student is my Mongoose Model.
我尝试重新安装node_modules,在github上搜索一些修复程序.
I've tried reinstalling my node_modules, searching some fix on the github.
这是我的变异函数
addStudent: async (
root,
{ studentId, firstName, lastName, email, password },
{ Student }
) => {
const newStudent = await new Student({
studentId,
firstName,
lastName,
email,
password
}).save();
return newStudent;
}
这是我的猫鼬模型
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const StudentSchema = new Schema({
studentId: {
type: String,
required: true
},
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
// sectionId: {
// type: [Schema.Types.ObjectId],
// ref: "Section",
// nullable: true
// },
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
createdDate: {
type: Date,
default: Date.now
}
});
module.exports = mongoose.model("Student", StudentSchema);
应该创建该学生,但是该消息会弹出该错误.
The student should be created, but that error pops up with that message.
推荐答案
已修复!我应该提供查询变量,而不是在graphql突变上手动输入
Fixed! I should have provided query variables rather than manual typing on the graphql mutation
这篇关于如何确定“猫鼬模型的名称"?变异时,它不是graphql中的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文