我为对象创建了一个枚举类型
const MonthType = new GraphQLEnumType({
name: 'monthType',
value: {
JANUARY:{
value: "January"
},
FEBRUARY: {
value: 'February'
},
MARCH: {
value: 'March'
},
MAY: {
value: 'May'
},
JUNE: {
value: 'June'
},
JULY: {
value: 'July'
},
AUGUST: {
value: "August"
},
SEPTEMBER: {
value: 'September'
},
OCTOBER: {
value: 'October'
},
NOVEMEBER: {
value: 'November'
},
DECEMBER: {
value: 'December'
}
}
})
我在对象类型中使用的是这样的
const UserType = new GraphQLObjectType({
name: 'User', // Importance of Name here
fields: () => ({
id: {
type: GraphQLInt
},
userId: {
type: GraphQLInt
},
gradMonth: {
type: MonthType
},
现在,无论何时启动快递服务器,我的代码都会抛出以下错误
monthType值必须是一个以值名称作为键的对象
我打算做什么?我希望用户选择并传递应该是其中之一的月份值。
有人可以帮我弄清楚为什么我得到以下错误吗?
答案 0 :(得分:2)
尝试在开始时用value
替换values
:
const MonthType = new GraphQLEnumType({
name: 'monthType',
values: { // <=== here
//...