Gh0*_*05d 4 node.js node-soap graphql graphql-js
我收到一个奇怪的错误,无法弄清楚我做错了什么。我写了一个graphql突变来调用一个api:
domainStuff: async (parent, { command, params }, { models }) => {
console.log("Params:", params);
const result = await dd24Api(command, params);
return result;
}
Run Code Online (Sandbox Code Playgroud)
这是我调用的函数:
export default async (command, parameter) => {
const args = _.merge({ params: parameter }, auth);
// Eleminate copying mistakes
console.log(typeof args);
const properCommand = command + "Async";
const result = await soap
.createClientAsync(apiWSDL)
.then(client => {
return client[properCommand](args)
.then(res => {
console.log(res[command + "Result"]);
return res[command + "Result"];
})
.catch(err => {
console.log(err);
return err;
});
})
.catch(err => console.log(err));
return result;
Run Code Online (Sandbox Code Playgroud)
使用此查询变量:
{
"command": "CheckDomain",
"params": {"domain": "test.it"}
}
Run Code Online (Sandbox Code Playgroud)
console.log 显示 args 是一个对象,但我收到此错误(来自第一个 catch 块):
TypeError: obj.hasOwnProperty is not a function
Run Code Online (Sandbox Code Playgroud)
怎么可能?毕竟我检查了它是否是一个对象,它是。更奇怪的是,如果我在查询中提供一个硬编码对象,例如:
domainStuff: async (parent, { command, params }, { models }) => {
console.log("Params:", params);
const result = await dd24Api(command, {domain: "test.com"});
return result;
}
Run Code Online (Sandbox Code Playgroud)
然后它工作得很好。我究竟做错了什么?感谢您提前获得任何帮助。
编辑:我正在使用“graphql-server-express”:“^0.8.0”和“graphql-tools”:“^1.0.0”
如果您正在使用graphql-js,有很多地方使用Object.create(null)不同于{}您可以在此处阅读有关使用 Object.create(null) 创建 Js 对象的说明创建新对象的地方?
但本质上创建的对象Object.create(null)没有 hasOwnProperty 方法
您可以在节点中尝试使用
const obj1 = Object.create(null)
console.log(typeof obj1.hasOwnProperty)
// 'undefined'
const obj2 = {}
console.log(typeof obj2.hasOwnProperty)
// 'function'
Run Code Online (Sandbox Code Playgroud)
可用于确定对象是否具有可用于创建的对象的键的另一种方法Object.create(null)是
function hasKey(obj, key) {
return Object.keys(obj).indexOf(key) !== -1
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7306 次 |
| 最近记录: |