"cannot query field 'id' on type CreateUser" with official Graphql tutorial
Asked Answered
K

1

5

I am following the graphql-python tutorial on https://www.howtographql.com/graphql-python/4-authentication/. However, I get 3 errors saying "Cannot query field \"id\" on type \"CreateUser\"." I basically copied all source code in the tutorial and I double-checked my Python code before posting here. And I used the same versions of Django, Graphene and other packages. I use Windows 10 and Python3.7. How can I pass the error?

Mutation:

mutation {
  createUser (
    username: "abc",
    email: "[email protected]",
    password: "123456"
  ){
    id
    username
    password
  }
}

Response:

{
  "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
        }
      ]
    }
  ]
}
Kingbolt answered 28/5, 2019 at 15:42 Comment(0)
P
8

You are missing a level in your query:

mutation {
  createUser (
    username: "abc",
    email: "[email protected]",
    password: "123456"
  ){
    user {
      id
      username
      password
    }
  }
}
Piave answered 28/5, 2019 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.