提问人:nb_nb_nb 提问时间:5/12/2023 更新时间:5/12/2023 访问量:118
在 graphQL 中将对象数组作为变量传递时出错
Error when passing array of objects as variable in graphQL
问:
我正在尝试将对象数组作为 graphQL 突变中的变量传递。变量从循环中填充,并将突变传递给公理函数。forEach
我的代码:
const query = "mutation myMutation($id: ID!, $label: String, $arr: [ArrInput]) {
createField(input: {
id: $id,
label: $label,
arr: $arr,
}) {
table_field {
id
label
}
}
}";
result.data.forEach(d=> {
const variables = {
label: d.label,
arr: d.arr,
};
axiosFunc({ query, variables }).then((response) => response);
});
arr
格式从:variables
"arr": [
{
"val1": "one",
"val2": {
"id": "349464"
}
},
{
"val1": "two",
"val2": {
"id": "374362"
}
},
]
错误信息
"errors": [
{
"message": "Variable $arr of type [ArrInput] was provided invalid value for 0.val2 (Field is not defined on ArrInput), 0.val2_id (Expected value to not be null), 1.val2 (Field is not defined on ArrInput), 1.val2_id (Expected value to not be null)
"locations": [
{
"line": 2,
"column": 185
}
],
我该如何解决这个问题?
答: 暂无答案
上一个:从对象分配给变量的更简洁的方法
评论
[{"val1": "one", "val2_id": "349464"}, {"val1": "two", "val2_id": "374362"}]
createField
ArrInput