Do you want to request a feature or report a bug?
What is the current behavior?
I use with Apollo server 2.0. when I want _id, but in response data, ObjectId is not converted to String.
What is the expected behavior?
How to auto convert ObjectId to String?
Please mention your node.js, mongoose and MongoDB version.
"mongoose": "^5.2.13",
node: 8
MongoDB: 3.6
GraphQL have used a new method to serialize ID, the new method doesn't support ID in object type anymore, but following codes will help on this:
const mongoose = require('mongoose');
const ObjectId = mongoose.Types.ObjectId;
ObjectId.prototype.valueOf = function () {
return this.toString();
};
Hope mongoose will support this feature soon :)
Interesting idea @Lanfei , will investigate that for a future release.
@vkarpov15 Nice, thanks :)
Hi any news about this?
@cannap #6912 should help with this, you'll be able to do:
mongoose.Schema.ObjectId.get(v => v != null ? v.toString() : v);
Does that API make sense?
@vkarpov15, definitely, great idea, waiting for 5.4 patiently.
Thanks for great middleware.
5.4.0 is out, here's the workaround
Most helpful comment
GraphQL have used a new method to serialize ID, the new method doesn't support ID in object type anymore, but following codes will help on this:
Hope mongoose will support this feature soon :)