官方Graphql教程“无法在CreateUser类型上查询字段'id'”

时间:2019-05-28 15:42:12

标签: graphql graphene-python graphql-python

我正在关注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
        }
      ]
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

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

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