phoenix-frameworkectoabsinthe

Why doesn't my registration mutation work with the role field?


Why doesn't my registration mutation work with the role field?

I written the following code but can't figure out why my role enum doesn't work with my mutation.

I uploaded my code to github Github code.

The registration mutation works:

mutation{
      registerUser(input:{email:"a@a.com", password:"a@a.com", role:"user",passwordConfirmation:"a@a.com"}){
        email

      }
    }

But when i try my login mutation it fails:

mutation{
  loginUser(input:{email:"a@a.com", password:"a@a.com", role:"user"}){
    token
    user{
      email
    }
  }
}

And I get this error::

"# KeyError at POST /api/graphiql\n\nException:\n\n    
** (KeyError) key :role not found in: %{email: \"a@a.com\", password: \"a@a.com\"}\n 

Solution

  • So what i was doing wrong was answered for me on the elixirforum by @benwilson512.

    The following assumption of mine that I can use field(:role, :user_input) to get the input type form my user_input was incorrect.

    If I want to pass down the role to my mutation the best way is to use field(:role, non_null(:string)) and treated as a string.

    But still i am not sure what is the best way to deal with this, although this solves the problem I was having.

    So thanks everyone that looked over my question.