Dustin Sun
Dustin Sun

Reputation: 5532

"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: "[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
        }
      ]
    }
  ]
}

Upvotes: 5

Views: 7421

Answers (1)

DavidG
DavidG

Reputation: 119056

You are missing a level in your query:

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

Upvotes: 8

Related Questions