【问题标题】:Not able to pass object in graphql mutation无法在 graphql 突变中传递对象
【发布时间】:2020-08-16 19:57:42
【问题描述】:

谁能告诉我如何从 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 

【问题讨论】:

  • 请提供代码以及您遇到的错误
  • 您好,请查找我添加的图片
  • 请阅读How to Ask。我们希望您在这里提供适当的问题描述;仅举起图片不被视为一种。

标签: node.js reactjs facebook-graph-api graph graphql-js


【解决方案1】:

我从您的问题中了解到的是,您希望将对象数组作为参数传递给突变。很容易做到。

首先在模式中定义一个输入,如下所示。它的值名称为字符串。你可以添加任何你想要的。此结构将用于将值作为参数传递。

    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"}])

【讨论】:

    猜你喜欢
    • 2020-05-05
    • 2020-02-03
    • 2020-09-22
    • 1970-01-01
    • 2017-03-09
    • 2019-11-19
    • 2017-08-22
    • 1970-01-01
    • 2018-02-07
    相关资源
    最近更新 更多