【问题标题】:values must be an object with value names as keysvalues 必须是一个以值名作为键的对象
【发布时间】:2019-07-31 23:18:05
【问题描述】:

我为我的对象创建了一个枚举类型

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 值必须是一个以值名作为键的对象

我打算做什么?我希望用户选择,传递应该是其中之一的月份的值。

有人可以帮我弄清楚为什么会出现以下错误吗?

【问题讨论】:

    标签: node.js express graph graphql


    【解决方案1】:

    尝试在开头将value 替换为values

    const MonthType = new GraphQLEnumType({
          name: 'monthType',
          values: { // <=== here
          //...
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2018-04-14
      • 2010-12-26
      • 1970-01-01
      • 2021-08-14
      • 2017-01-17
      • 2012-02-03
      • 1970-01-01
      相关资源
      最近更新 更多