Ivan Asmer 5 yıl önce
ebeveyn
işleme
b994cb09f3
2 değiştirilmiş dosya ile 4 ekleme ve 10 silme
  1. 1 1
      index.js
  2. 3 9
      models.js

+ 1 - 1
index.js

@@ -213,7 +213,7 @@ const anonResolvers = ['login', 'createUser'];
         }
         const operationMatch = gql.query.match(/\{\s*([a-zA-Z]+)\s*/)
         const operationName  = gql.operationName || operationMatch[1]
-        console.log('before oper', operationName, operationMatch)
+        console.log('before oper', operationName)
         if ((!operationName) || anonResolvers.includes(operationName)){
             return {
                 schema: schema,

+ 3 - 9
models.js

@@ -1,16 +1,10 @@
 const MongoClient = require("mongodb").MongoClient;
 const ObjectID    = require("mongodb").ObjectID;
 const mm          = require('mm')
+const {connect}          = require('mm')
 
-module.exports = async (dbName, dsn="mongodb://localhost:27017/") => {
-    if (!dbName)
-        throw new ReferenceError(`db name does not provided`)
-
-    const mongoClient = new MongoClient(dsn, { useNewUrlParser: true });
-    const client      = await mongoClient.connect()
-    const db          = client.db(dbName)
-    const Savable     = mm(db).Savable
-    const slice       = mm(db).sliceSavable 
+module.exports = async (dbName='cb') => {
+    const {Savable, slice} = await connect(dbName)
 
     async function getModels(id){
         const SlicedSavable = slice([id, 'user'])