I use moongose
for work with mongodb
on nodejs
based app. Currently, I try to implement Grapqhl
based API.
My query graphql
schema looks like:
const schema = buildSchema(`
type Query {
predictionModels(active: Boolean): [PredictionModel]
},
type PredictionModel {
_id: ID
title: String
active: Boolean
}
`)
but when I use:
query {
predictionModels(active: true){
_id
}
}
As the response I get:
"errors": [
{
"message": "ID cannot represent value: 5a72240cf31713598588b70f",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"predictionModels",
0,
"_id"
]
} ....
Prediction model mongoose schema:
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}
})
1
This message shows up if the value provided for
_id
is neither a string nor an integer. Mongoose object id fields should be properly serialised by graphql-js by this function. Can you add your mongoose model?Oct 25, 2018 at 10:21