我试图在我的graphql解析器中调用多个aysnc await,它继续告诉我 Promise或函数不是函数。所以我尝试用相同的结果调用常规函数。我甚至尝试通过连接器传递函数而不仅仅是导入,结果仍然相同......这里是代码片段的一个示例:
import { clientdb, driver, fse } from './connectors';
.
..
...
....
createClient: async(parent, args, { Client }) => {
const singleclient = await new clientdb(args.client).save(); //this line works
const spawndb = await new fse.copy('c:/databases/default.graphdb', 'c:/databases/dbName.graphdb'); //this gives an error
},
TypeError: Cannot read property 'copy' of undefined
at _callee3$ (C:/Users/ADMIN/Desktop/GenysisGQL/server/resolvers.js:150:39)
at tryCatch (C:\Users\ADMIN\Desktop\GenysisGQL\node_modules\regenerator-runtime\runtime.js:65:40)
at Generator.invoke [as _invoke] (C:\Users\ADMIN\Desktop\GenysisGQL\node_modules\regenerator-runtime\runtime.js:299:22)
clientdb是从./connectors
导入的mongodb驱动程序const clientdb = mongoose.model('client', clientSchema);
fse.copy来自fs-extra
let orgCode = getHashKey(org, max); //this is a regular function...same error
TypeError: (0 , _gethashkey.gethashkey) is not a function
at _callee3$ (C:/Users/ADMIN/Desktop/GenysisGQL/server/resolvers.js:158:23)
at tryCatch (C:\Users\ADMIN\Desktop\GenysisGQL\node_modules\regenerator-runtime\runtime.js:65:40)
at Generator.invoke [as _invoke] (C:\Users\ADMIN\Desktop\GenysisGQL\node_modules\regenerator-runtime\runtime.js:299:22)
我确实做过TypeOf检查,我的功能不再是Aysnc内部的功能。问题是为什么当mongoDB驱动程序没问题时这些功能不再起作用。他们为什么被区别对待?
答案 0 :(得分:1)
显然我被fs-extra docs误导了...... fs-extra毕竟不是一个承诺。一个人必须使用fs-extra-plus或fs-extra-promise-es6。几个小时后发现这个,然后开始怀疑文档。