批量插入中的空值 Hasura GraphQL
Null value in bulk insert Hasura GraphQL
我正在尝试使用由 Hasura(用 GraphQL 编写)公开的 REST API 进行多次插入。
这是我的突变:
mutation insertMultipleMeasurements2($payload: [measurements_insert_input!]!) {
insert_measurements(objects: $payload) {
returning {
time
}
}
}
这是“操作”选项卡中 measurements_insert_input 的定义:
input measurements_insert_input {
device: String!
value: numeric!
variable: String!
}
(顺便说一下,这是我发现在批量插入中插入数字类型对象的唯一方法)。
当我尝试插入如下内容时:
[
{
"device": "TEST",
"value": 5630,
"variable": "Length"
},
{
"device": "TEST",
"value": 5631,
"variable": "Length"
}
]
我得到:
{
"path": "$",
"error": "expecting a value for non-nullable variable: \"payload\"",
"code": "validation-failed"
}
我尝试了许多不同的方法来重写我的突变,但看起来 none 有效。
提前致谢
根据错误信息
"expecting a value for non-nullable variable: "payload""
您应该通过对象传递数组
{
payload: [
{
"device": "TEST",
"value": 5630,
"variable": "Length"
},
{
"device": "TEST",
"value": 5631,
"variable": "Length"
}
]
}
你很可能忘记用 variables
包裹你的 objects
,像这样:
yourMutation({
variables: { objects, on_conflict }
})
如果你依赖 TS IntelliSense,这并不简单,最好查看文档 :)
我正在尝试使用由 Hasura(用 GraphQL 编写)公开的 REST API 进行多次插入。 这是我的突变:
mutation insertMultipleMeasurements2($payload: [measurements_insert_input!]!) {
insert_measurements(objects: $payload) {
returning {
time
}
}
}
这是“操作”选项卡中 measurements_insert_input 的定义:
input measurements_insert_input {
device: String!
value: numeric!
variable: String!
}
(顺便说一下,这是我发现在批量插入中插入数字类型对象的唯一方法)。
当我尝试插入如下内容时:
[
{
"device": "TEST",
"value": 5630,
"variable": "Length"
},
{
"device": "TEST",
"value": 5631,
"variable": "Length"
}
]
我得到:
{
"path": "$",
"error": "expecting a value for non-nullable variable: \"payload\"",
"code": "validation-failed"
}
我尝试了许多不同的方法来重写我的突变,但看起来 none 有效。 提前致谢
根据错误信息
"expecting a value for non-nullable variable: "payload""
您应该通过对象传递数组
{
payload: [
{
"device": "TEST",
"value": 5630,
"variable": "Length"
},
{
"device": "TEST",
"value": 5631,
"variable": "Length"
}
]
}
你很可能忘记用 variables
包裹你的 objects
,像这样:
yourMutation({
variables: { objects, on_conflict }
})
如果你依赖 TS IntelliSense,这并不简单,最好查看文档 :)