繁体   English   中英

为什么我不能在我的 graphql 解析器中调用函数

[英]why can't I call a function inside my graphql resolvers

我试图在我的 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 驱动程序正常时这些不再起作用。 为什么他们会受到不同的对待?

显然,我被 fs-extra 文档严重误导了......毕竟 fs-extra 不是一个承诺。 必须使用 fs-extra-plus 或 fs-extra-promise-es6。 几个小时后发现这一点,然后开始怀疑文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM