diff --git a/packages/strapi-hook-mongoose/lib/utils/index.js b/packages/strapi-hook-mongoose/lib/utils/index.js index bed5daabb3..2e0ff1412e 100644 --- a/packages/strapi-hook-mongoose/lib/utils/index.js +++ b/packages/strapi-hook-mongoose/lib/utils/index.js @@ -8,7 +8,17 @@ const mongoose = require('mongoose'); const Mongoose = mongoose.Mongoose; +/** + * Convert MongoDB ID to the stringify version as GraphQL throws an error if not. + * + * Refer to: https://github.com/graphql/graphql-js/commit/3521e1429eec7eabeee4da65c93306b51308727b#diff-87c5e74dd1f7d923143e0eee611f598eR183 + */ +mongoose.Types.ObjectId.prototype.valueOf = function () { + return this.toString(); +}; + module.exports = (mongoose = new Mongoose()) => { + const Decimal = require('mongoose-float').loadType(mongoose, 2); const Float = require('mongoose-float').loadType(mongoose, 20);