提问人:nb_nb_nb 提问时间:4/29/2023 最后编辑:nb_nb_nb 更新时间:4/29/2023 访问量:98
从 graphql 响应创建对象数组
Create array of objects from graphql response
问:
我有一个来自 graphql 的响应,我想重新格式化并分配给一个变量,以便我可以在我的应用程序中继续使用它们。
GraphQL 响应:
{
"data": {
"organization": {
"tables": {
"edges": [
{
"node": {
"id": "1wer45",
"name": "Node One",
"internal_id": "12345"
}
},
{
"node": {
"id": "j8IrxJ425",
"name": "Node Two",
"internal_id": "54321"
}
}
]
}
}
}
}
我想将以下格式分配给数组:
[
"Node One": { id: '1wer45', internal_id: '12345' }
"Node Two": { id: 'j8IrxJ425', internal_id: '54321' }
]
我希望将上述内容分配给一个可以继续重用的数组。
我的代码:
const reFormat = func((result) => {
let test = {};
let obj1 = {};
let table_details = result.data.data.organization.tables.edges.map((d) => {
obj1["id"] = d.node.id;
obj1["internal_id"] = d.node.internal_id;
test[d.node.name] = obj1;
return test;
});
console.log(table_details);
});
reFormat({ query: tables("13456") }).then((res) => res);
它没有给我一个错误,但也没有给我我想要的东西。我想将重新格式化的数组分配给变量。
答: 暂无答案
评论
pipefyFunction
console.log
return
.then((res) => res)
obj1 = {}
map
test
table_details
for
test
tables { edges { node { … } } }
tables { nodes { … } }