我正在使用 Nodejs 调用一个报告 API,它给我一个 JSON 响应。可以使用不同的 ID(在本例中为不同的报告 ID)调用 api。例如:
https://report.domain.io/report/1
https://report.domain.io/report/2
Run Code Online (Sandbox Code Playgroud)
等等。由于id在不同的时间不同,它会给我不同的反应。属性名称会有所不同。所以我不能在 GraphQLObjectType 中映射它。例如,如果 JSON 响应如下:
[
{
"modelbrand": "Sony",
"modelcode": "F3111",
"avg_free_storage": 225401514
},
{
"modelbrand": "Sony",
"modelcode": "F3111",
"avg_free_storage": 224547840
}
]
Run Code Online (Sandbox Code Playgroud)
然后我可以用 GraphQL 映射它,如下所示:
Report() {
return new graphql.GraphQLObjectType({
name: "Report",
description: "This represents report",
fields: () => ({
"modelbrand": {type: graphql.GraphQLString},
"modelcode": {type: graphql.GraphQLString},
"avg_free_storage": {type: graphql.GraphQLString}
})
});
}
Run Code Online (Sandbox Code Playgroud)
因为我知道属性是固定的。但是,如果属性名称如 modelbrand、modelcode 更改为其他内容(显然不同的报告会有所不同),那么我无法在 GraphQLObjectType 中映射它。在这种情况下,我需要另一种类型(应该是 JSON 类型)来映射这些响应。不幸的是,它不能用作 GraphQL 的原始类型。我没有找到任何自定义/标量类型或节点库来解决这个问题。堆栈溢出有一个解决方案,但似乎不起作用。
我能得到一个解决方案吗?一个 Nodejs 示例将不胜感激。谢谢。
如何一次从AWS Systems Manager(参数存储)中批量获取参数(或多个参数)?使用aws-sdk,以下是我编写的从参数存储中检索SSM参数的Node.js代码:
const ssm = new (require('aws-sdk/clients/ssm'))()
const getSSMKey = async params => {
const {Parameter: {Value: APIKey}} = await ssm.getParameter(params).promise()
return APIKey
}
const [param1, param2, param3] = await Promise.all([
getSSMKey({ Name: '/data/param/PARAM1', WithDecryption: true }),
getSSMKey({ Name: '/data/param/PARAM2', WithDecryption: true }),
getSSMKey({ Name: '/data/param/PARAM3', WithDecryption: true })
])
console.log(param1, param2, param3)
Run Code Online (Sandbox Code Playgroud)
但是使用此代码,我正在发送3个请求以获取3个参数,这在大量参数的情况下效率低下。有什么方法可以在一个请求中检索多个参数。如果ssm.getParameters()是执行此操作的方法,请举一个示例(特别是该方法的参数)。我尝试过,但是什么也没收到。
输入xml文件:
<?xml version="1.0"?>
<res:testcases xmlns:res="urn:testcases" id="a1e4bfdb-40a2-485c-a1ac-54d220056dd5" type="MODEL">
<mode>PRESSURE_CONTROL</mode>
<category>ADULT</category>
<testcase id="1" type="UNIQUE">
<parameter id="PEEP" value="1.0">true</parameter>
<parameter id="CMV_FREQ" value="4.0">true</parameter>
<parameter id="PRESS_ABOVE_PEEP" value="0.0">true</parameter>
<parameter id="I_E_RATIO" value="0.1">false</parameter>
</testcase>
</res:testcases>
Run Code Online (Sandbox Code Playgroud)
Python代码:
import xml.etree.ElementTree as ET
tree = ET.parse('/home/AlAhAb65/Desktop/input.xml')
root = tree.getroot()
root.attrib['type'] = 'AVA'
tree.write('/home/AlAhAb65/Desktop/output1.xml')
Run Code Online (Sandbox Code Playgroud)
输出xml文件:
<ns0:testcases id="a1e4bfdb-40a2-485c-a1ac-54d220056dd5" type="AVA" xmlns:ns0="urn:testcases">
<mode>PRESSURE_CONTROL</mode>
<category>ADULT</category>
<testcase id="1" type="UNIQUE">
<parameter id="PEEP" value="1.0">true</parameter>
<parameter id="CMV_FREQ" value="4.0">true</parameter>
<parameter id="PRESS_ABOVE_PEEP" value="0.0">true</parameter>
<parameter id="I_E_RATIO" value="0.1">false</parameter>
</testcase>
</ns0:testcases>
Run Code Online (Sandbox Code Playgroud)
问题是当我复制并写入输出xml文件时,意外的事情发生了.它们如下所示:1.输入xml文件的第一行自动删除2.在第二行(输入中),文本'res'替换为'ns0'.关闭标签3时也是如此.属性(第二行输入)的顺序发生了变化.但我想写(作为输出)我作为输入获得的xml文件的精确副本.请帮助我这方面.
我有两个E类型列表List list1,List list2.E对象是一个POJO类,包含一行以下数据.两个列表都包含相同的数据.例如,在最后一列,如果我将false更改为true,则无法检测到.
| statusId | statusName | statusState | isRequire |
| 3 | Approved | APPROVED | false |
| 201 | Attributed | REJECTED | true |
| 202 | Denied | REJECTED | false |
| 204 | Fraud | REJECTED | false |
| 205 | Insufficient | REJECTED | false |
| 206 | Invalid | REJECTED | false |
| 207 | Cancelled | REJECTED | false |
| 208 | Cannot traced …Run Code Online (Sandbox Code Playgroud)