[谁能告诉我如何从react js端传递graphql突变的对象数组。我试图在react中传递对象,但得到的错误类型不同。
[input type][1]
[from api side][2]
[declaring the object][3]
[passing object in mutation][4]
[error i'm facing][5]
[1]: https://i.stack.imgur.com/ufVtA.png
[2]: https://i.stack.imgur.com/kQt5m.png
[3]: https://i.stack.imgur.com/hnxLM.png
[4]: https://i.stack.imgur.com/5JCHf.png
[5]: https://i.stack.imgur.com/BonPE.png
我从您的问题中了解到的是,您希望将对象数组作为参数传递给突变。这可以轻松完成。
首先在架构中定义输入,如下所示。它的值名称为字符串。您可以添加任何所需的内容。此结构将用于传递值作为参数。
input Product {
name: String
}
上面创建的输入将作为数组传递,如下所示。
type RootMutation{
createProduct(product: [Product]): String
}
您将在解析器中获取数据
createProduct: (args)=>{
// You will get the value in this 'args'
// Do Whatever you want
}
输入如下
createProduct(product:[{name:"has"}])