scratch/mongo-plugin.js
function mongoType(
  typeStr,
  options
) {
  const required = typeStr.match(/^(\S+)!$/);
  const list = typeStr.match(/^\[(\S+)]$/);

  if (required) {
    const innerType = required[1];
    if (_.includes(SCALARS, innerType)) {
      options.required = true;
    }
    return mongoType(innerType);
  } else if (list) {
    return [ mongoType(list[1]) ];
  }
  switch (typeStr) {
    case 'String':
      return String;
    case 'Int':
    case 'Float':
      return Number;
    case 'Boolean':
      return Boolean;
    case 'DateTime':
      return Date;
    case 'ID':
      return mongoose.Schema.Types.ObjectId;
    case 'JSON':
      return mongoose.Schema.Types.Mixed;
    default:
      throw new Error(typeStr);
  }
}
function mongoType(
  typeStr,
  options
) {
  const required = typeStr.match(/^(\S+)!$/);
  const list = typeStr.match(/^\[(\S+)]$/);

  if (required) {
    const innerType = required[1];
    if (_.includes(SCALARS, innerType)) {
      options.required = true;
    }
    return mongoType(innerType);
  } else if (list) {
    return [ mongoType(list[1]) ];
  }
  switch (typeStr) {
    case 'String':
      return String;
    case 'Int':
    case 'Float':
      return Number;
    case 'Boolean':
      return Boolean;
    case 'DateTime':
      return Date;
    case 'ID':
      return mongoose.Schema.Types.ObjectId;
    case 'JSON':
      return mongoose.Schema.Types.Mixed;
    default:
      throw new Error(typeStr);
  }
}
function mongoType ( typeStr , options ) { const required = typeStr . match ( / ^(\S+)!$ / ) ; const list = typeStr . match ( / ^\[(\S+)]$ / ) ; if ( required ) { const innerType = required [ 1 ] ; if ( _ . includes ( SCALARS , innerType ) ) { options . required = true ; } return mongoType ( innerType ) ; } else if ( list ) { return [ mongoType ( list [ 1 ] ) ] ; } switch ( typeStr ) { case 'String' : return String ; case 'Int' : case 'Float' : return Number ; case 'Boolean' : return Boolean ; case 'DateTime' : return Date ; case 'ID' : return mongoose . Schema . Types . ObjectId ; case 'JSON' : return mongoose . Schema . Types . Mixed ; default : throw new Error ( typeStr ) ; } }
Translates a graphql scalar type to a valid mongoose type
@param {*} typeStr
@param {*} options
Translates a graphql scalar type to a valid mongoose type