GraphQL:消息:ID不能表示值:5a72240cf31713598588b70f" [英] Graphql: "message": "ID cannot represent value: 5a72240cf31713598588b70f"

查看:9
本文介绍了GraphQL:消息:ID不能表示值:5a72240cf31713598588b70f"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用moongosenodejs上使用mongodb。目前,我正在尝试实现基于Grapqhl的API。

我的查询graphql架构如下:

const schema = buildSchema(`                                                 
    type Query {                                                            
      predictionModels(active: Boolean): [PredictionModel]
    },                                                                                   
    type PredictionModel {                                                                                                 
        _id: ID                                                                                                             
        title: String
        active: Boolean                                                                                                
    }                                                                                                      
`)  

但当我使用:

query {
  predictionModels(active: true){
    _id
  }
}

作为我得到的响应:

"errors": [
    {
      "message": "ID cannot represent value: 5a72240cf31713598588b70f",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "predictionModels",
        0,
        "_id"
      ]
    } ....

预测模型Mongoose架构:

const predictionModelSchema = new Schema({                                                                              
    title: { type: String, require: true, unique: true },                                                               
    modelId: { type: String, require: true, unique: true },                                                             
    description: { type: String, unique: true },                                                                        
    language: {type: String, enum: [ProgrammingLanguage.JS, ProgrammingLanguage.R], require: true},                     
    estimates: [{ type : Schema.Types.ObjectId, ref: 'PredictionModelEstimate'}],                                                                                             
    method: { type: methodType, require: true},                                                                         
    active: { type: Boolean, require: true}                                                                             
})

推荐答案

如果这是类型问题,您可以使用:

var ObjectId = require('mongoose').Types.ObjectId;
_id: new ObjectId(ID)

这篇关于GraphQL:消息:ID不能表示值:5a72240cf31713598588b70f"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆