Я получаю ошибку "Cannot read property 'get' of undefined"
только когда я добавляю product
Массив объектов к мутации, если я только добавляю orderId
Int, ошибки нет. Ниже приведены дополнительные сведения:
Схема
type Order {
orderId: Int
product: [ProductInput]
}
input ProductInput {
prodId: String
value: [ValueInput]
}
type Product {
prodId: String
value: [Value]
}
type Value{
name:String,
props:String
}
input ValueInput{
name:String,
props:String
}
Мутация
addOrder(orderId: Int, product: [ProductInput]):Order
Resolver (с пн goose)
addOrder(parent, args, context, info) {
let orderId;
let product;
if (args.orderId) {
orderId = { orderId: args.orderId };
}
if (args.product) {
product= { product: args.product};
}
return context.Order.findOneAndUpdate(
{ orderId: args.orderId },
{
$setOnInsert: {
...orderId,
...product
}
},
{ new: true, upsert: true }
);
}
Чет я получить ошибку, мутация успешно в базе данных, но graphql вернуть
{
"errors": [
{
"message": "Cannot read property 'get' of undefined",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"addOrder"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot read property 'get' of undefined",
" at EmbeddedDocument.<anonymous> (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\schema.js:1824:23)",
" at VirtualType.applyGetters (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\virtualtype.js:137:25)",
" at EmbeddedDocument.Document.get (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\document.js:1508:19)",
" at applyVirtuals (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\document.js:3246:20)",
" at EmbeddedDocument.Document.$toObject (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\document.js:2986:5)",
" at EmbeddedDocument.Document.toObject (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\document.js:3169:15)",
" at DocumentArrayPath.cast (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\schema\\documentarray.js:401:27)",
" at DocumentArrayPath.SchemaType.applySetters (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\schematype.js:1010:12)",
" at DocumentArrayPath.SchemaType._castForQuery (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\schematype.js:1424:15)",
" at DocumentArrayPath.SchemaType.castForQueryWrapper (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\schematype.js:1391:17)",
" at castUpdateVal (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\helpers\\query\\castUpdate.js:515:19)",
" at walkUpdatePath (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\helpers\\query\\castUpdate.js:342:22)",
" at castUpdate (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\helpers\\query\\castUpdate.js:99:18)",
" at model.Query._castUpdate (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\query.js:4481:10)",
" at castDoc (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\query.js:4509:18)",
" at model.Query.Query._findAndModify (C:\\Users\\mihai\\Desktop\\Projects\\ECOM\\BACKEND\\node_modules\\mongoose\\lib\\query.js:3472:22)"
]
}
}
}
],
"data": {
"addOrder": null
}
}