From 4a7cae4ac0d4edadef5c135eb8e486ba3d35f5b5 Mon Sep 17 00:00:00 2001 From: Kamal Bennani Date: Mon, 19 Nov 2018 21:47:48 +0100 Subject: [PATCH] Stringify ObjectID --- packages/strapi-hook-mongoose/lib/utils/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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);