【问题标题】:"cannot query field 'id' on type CreateUser" with official Graphql tutorial带有官方 Graphql 教程的“无法在 CreateUser 类型上查询字段 'id'”
【发布时间】:2019-10-14 04:36:09
【问题描述】:

我正在关注https://www.howtographql.com/graphql-python/4-authentication/ 上的 graphql-python 教程。但是,我收到 3 个错误,提示“无法在类型 \"CreateUser\" 上查询字段 \"id\"。”我基本上复制了教程中的所有源代码,并在此处发布之前仔细检查了我的 Python 代码。并且我使用了相同版本的 Django、Graphene 和其他包。我使用 Windows 10 和 Python3.7。如何传递错误?

变异:

mutation {
  createUser (
    username: "abc",
    email: "abc@example.com",
    password: "123456"
  ){
    id
    username
    password
  }
}

回复:

{
  "errors": [
    {
      "message": "Cannot query field \"id\" on type \"CreateUser\".",
      "locations": [
        {
          "line": 7,
          "column": 5
        }
      ]
    },
    {
      "message": "Cannot query field \"username\" on type \"CreateUser\". Did you mean \"user\"?",
      "locations": [
        {
          "line": 8,
          "column": 5
        }
      ]
    },
    {
      "message": "Cannot query field \"password\" on type \"CreateUser\".",
      "locations": [
        {
          "line": 9,
          "column": 5
        }
      ]
    }
  ]
}

【问题讨论】:

    标签: graphql graphene-python graphql-python


    【解决方案1】:

    您的查询中缺少一个级别:

    mutation {
      createUser (
        username: "abc",
        email: "abc@example.com",
        password: "123456"
      ){
        user {
          id
          username
          password
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-17
      • 2021-11-13
      • 2016-12-05
      • 2019-10-09
      • 2020-10-29
      • 2021-04-10
      • 2019-06-11
      • 2021-09-02
      • 2020-02-28
      相关资源
      最近更新 更多