【发布时间】:2021-11-20 23:43:41
【问题描述】:
我想将多个数据(对象数组)从输入动态发送到 apollo graphql 突变,但还没有找到可行的方法。 现在我仍然像下面的代码示例一样手动编写它。
我制作的示例代码:
变异
mutation createData(
$userId: Int!,
$Content: String,
$Title: String
) {
createData(
input: {
content: $Content
filterMetas: [
// how to make this dynamic from user input?
{ categoryName: "Category Name 1", categoryId: "1", categoryType: INFO }
{ categoryName: "Category Name 2", categoryId: "2", categoryType: INFO }
]
meta: { title: $Title }
}
userId: $userId
) {
id
name
}
在反应中调用突变
CreateData({
variables: {
Content: content,
Title: title,
// how to send multiple filtersMetas(array of objects) from here? instead of entering it manually
},
context: { clientName: API_CLIENT },
});
谢谢。
【问题讨论】:
-
像任何其他变量一样,您甚至可以使用一个变量发送所有变量,整个
$input
标签: reactjs graphql apollo-client