Closed bdanzer closed 2 years ago
Is meal1, snack1, etc a type? I am slightly confused with your schema. mixing object instances with types? Your schema is the same as your data.
Is meal1, snack1, etc a type? I am slightly confused with your schema. mixing object instances with types? Your schema is the same as your data.
Are you talking about this?
product: {
type: mongoose.Schema.Types.ObjectId,
ref: "Product",
},
I'm sure the mongoose schema I have is fine because if I use mongoose populate the way you would normally do it works. It's just with this library I am unsure how I should be using projection:
NutritionLogTC
.addRelation("product", {
resolver: () => ProductTC.getResolver("findByIds"),
prepareArgs: {
_ids: (source) => {
let ids = [];
console.log('source', source);
if (source.meal1.data) {
source.meal1.data.forEach(mealItem => ids.push(mealItem.product));
}
// console.log("SOURCE IS HERE", source.product);
return ids || [];
},
},
projection: {
meal1: {
data: {
product: true
}
}
}, // point fields in source object, which should be fetched from DB
});
What does return ids have in it? Is it an array of ids
Ok ended up figuring out what I was doing wrong. Funnily enough it was just that I had an invalid graphql query above in my document that I forgot about. Hence the GRAPHQL_VALIDATION_FAILED
validation error I got. So apologize for opening an issue on a mistake that dumb haha.
Hello, I have been having a bit of trouble figuring out how to do a proper projection on some of my nested ids on my object.
Here is my model:
And here is where I am adding my relation
Here is what my query looks like:
And here is part of the error I get back:
Here is what my mongo document looks like:
Any help is appreciated, thanks!