用猫鼬在graphql中强制转换为数组失败

时间:2018-09-24 10:55:01

标签: mongodb mongoose schema graphql

我有一个使用mongo,mongoose和graphql的简单项目。问题出现以下突变以及执行此突变时出现错误:

  

变异{createTitle(输入:{       名称:“ Trophy1”,       运动:“足球”,       类别:“国际”,       成立时间:1900年,       mostWinner:[{sport:“ Soccer”}]}){       名称       运动       类别       initYear}}

     

{“错误”:[       {         “ message”:“标题验证失败:mostWinner:在路径\” mostWinner \“”处的值\“ [{sport:'Soccer'}] \”的强制转换为Array失败,         “位置”:[           {             “行”:30,             “栏”:3           }         ],         “路径”:[           “ createTitle”         ]       }],“数据”:{       “ createTitle”:null}}

现在输入代码:

标题模型:

import mongoose from 'mongoose';
import {TeamSchema} from './team';
const Schema = mongoose.Schema;
const TitleSchema = new Schema({
    name: {type: String, required: true},
    sport: {type: String, required: true},
    category: {type: String},
    initYear: {type: Number},
    mostWinner: {type: [TeamSchema], default: []}
});
module.exports = {
    TitleModel:mongoose.model('title', TitleSchema),
    TitleSchema:TitleSchema

}

团队模型:

import mongoose from 'mongoose';
import {TitleSchema} from './title';
import {TeamTitleSchema} from './teamTitle';
const Schema = mongoose.Schema;
const TeamSchema = new Schema({
    name: {type: String, required: true},
    sport: {type: String, required: true},
    shield: {type: String}, //Change to buffer in future
    yearFundation: {type: Number},
    teamTitle: {type: [TeamTitleSchema], default: []}
});

module.exports = {
    TeamModel:mongoose.model('team', TeamSchema),
    TeamSchema:TeamSchema

}

有人可以帮助我吗? 谢谢

0 个答案:

没有答案