【问题标题】:Cannot fetch array of strings无法获取字符串数组
【发布时间】:2020-05-16 03:05:22
【问题描述】:

您好,我正在尝试通过 graphQL 在我的 mongoDB 集合中获取一些数据,

这是我的 graphQl 架构:

type Account {
  _id: String
  id: String
  account_id: Int
  limit: Int!
  products: [String]
}

type Query {
  account(_id: String): [Account]
}

这是解析器返回的控制台日志

[ { _id: 5ca4bbc7a2dd94ee58162a49,
    account_id: 142442,
    limit: 9000,
    products:
     [ 'Commodity',
       'CurrencyService',
       'Derivatives',
       'InvestmentFund',
       'InvestmentStock' ],
    id: '5ca4bbc7a2dd94ee58162a49' } ]

但这是从 graphiQL 返回的查询

{
  "data": {
    "account": [
      {
        "id": "5ca4bbc7a2dd94ee58162a49",
        "_id": "5ca4bbc7a2dd94ee58162a49",
        "account_id": null,
        "limit": 9000,
        "products": null
      }
    ]
  }
}

我不明白为什么我的 products 和 account_id 字段返回空值,它们似乎具有正确的类型,我错过了什么吗?

【问题讨论】:

    标签: javascript node.js mongodb graphql


    【解决方案1】:

    好吧,没关系,问题出在猫鼬模式中,我忘了添加这些字段

    const accounts = new Schema({
        limit: Number,
        products: [String],
        account_id: Number
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 1970-01-01
      • 2013-08-22
      • 2016-06-30
      相关资源
      最近更新 更多