'use strict';

/**
 * Module dependencies
 */

// Public node modules.
const mongoose = require('mongoose');
const Mongoose = mongoose.Mongoose;

module.exports = (mongoose = new Mongoose()) => {
  const Decimal = require('mongoose-float').loadType(mongoose, 2);
  const Float = require('mongoose-float').loadType(mongoose, 20);

  return {
    convertType: mongooseType => {
      switch (mongooseType.toLowerCase()) {
        case 'array':
          return Array;
        case 'boolean':
          return 'Boolean';
        case 'binary':
          return 'Buffer';
        case 'date':
        case 'datetime':
        case 'time':
        case 'timestamp':
          return Date;
        case 'decimal':
          return Decimal;
        case 'float':
          return Float;
        case 'json':
          return 'Mixed';
        case 'biginteger':
        case 'integer':
          return 'Number';
        case 'uuid':
          return 'ObjectId';
        case 'email':
        case 'enumeration':
        case 'password':
        case 'string':
        case 'text':
          return 'String';
        default:
      }
    },
    valueToId: function (value) {
      return this.isMongoId(value)
        ? mongoose.Types.ObjectId(value)
        : value;
    },
    isMongoId: function (value) {
      // Here we don't use mongoose.Types.ObjectId.isValid method because it's a weird check,
      // it returns for instance true for any integer value ¯\_(ツ)_/¯
      const hexadecimal = /^[0-9A-F]+$/i;
      return hexadecimal.test(value) && value.length === 24;
    }
  };
};

@@ -139,16 +139,338 @@
 goose;%0A%0A
+/**%0A * Convert MongoDB ID to the stringify version as GraphQL throws an error if not.%0A *%0A * Refer to: https://github.com/graphql/graphql-js/commit/3521e1429eec7eabeee4da65c93306b51308727b#diff-87c5e74dd1f7d923143e0eee611f598eR183%0A */%0Amongoose.Types.ObjectId.prototype.valueOf = function () %7B%0A  return this.toString();%0A%7D;%0A%0A
 module.e
@@ -511,16 +511,17 @@
 )) =%3E %7B%0A
+%0A
   const 

Stringify ObjectID