【问题标题】:Strapi graphql mutationStrapi graphql 突变
【发布时间】:2021-03-09 19:23:15
【问题描述】:

我正在使用 Strapi 作为无头 CMS

我创建了一个客户内容类型并安装了 graphql 插件。

我正在尝试在 graphql 游乐场中创建一个突变以创建一个新客户

mutation createCustomer($username: String!, $email: String, $password: String){
  createCustomer(username: $username, email: $email, password: $password){
    _id username email password
  }
}

我在查询变量中传递用户名等

{ "username": "user1" }
{ "email": "User1@test.com" }
{"password":"123456"}   

我收到了错误

"message": "Unknown argument \"username\" on field \"createCustomer\" of type \"Mutation\".",

如果我查看文档,它看起来像。

如何编写突变来创建新客户

【问题讨论】:

  • 你检查用户许可了吗?
  • 是的,权限都设置好了

标签: graphql strapi mutation


【解决方案1】:

该错误表明在突变的查询组件中缺少对客户类型的引用。

另外,我相信您缺少“输入:”和“数据:”。我知道使用 createUser 时需要这些。

举例:

mutation createCustomer($username: String!, $email: String, $password: String) {
  createCustomer(
    input: { data: { username: $username, email: $email, password: $password } }
  ) {
    customer {
      id
      username
      email
      password
    }
  }
}

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2020-06-26
    • 2020-01-22
    • 2018-10-22
    • 2020-03-09
    • 2019-01-23
    • 2018-10-16
    • 2020-02-18
    • 2019-06-18
    相关资源
    最近更新 更多