graphqlgraphene-pythongraphql-python

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


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: "abc@example.com",
    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
        }
      ]
    }
  ]
}

Solution

  • You are missing a level in your query:

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