`schema.graphql` ``` type User { id: ID! @unique...
# orm-help
h
schema.graphql
Copy code
type User {
  id: ID! @unique
  email: String!
  password: String!
  role: Role @default(value: "CANDIDATE")
}
prisma.graphql
Copy code
type Query{
  user(where: UserWhereUniqueInput!): User
}
 input UserWhereUniqueInput {
  id: ID
}
I want to find the user on the based on email. Prisma did not add the email field in the
UserWhereUniqueInput
type
Copy code
async function login(root, { email, password }, ctx, info) {
    const user = await ctx.db.query.user({ where: { email: email } }, ` { id password } `)
    ....
}
I received this error message from Prisma Playground
Copy code
{
  "data": null,
  "errors": [
    {
      "message": "Variable \"$_v0_where\" got invalid value {\"email\":\"<mailto:Jane2@email.com|Jane2@email.com>\"}; Field \"email\" is not defined by type UserWhereUniqueInput.",
      "locations": [],
      "path": []
    }
  ]
}
can anyone help me?
a
I'm guessing (could be wrong) that it's because
email
is not
unique
and if you look at input type for
UserWhereUniqueInput
, you need some unique key 🙂
👍 2
In other words, if you want to be able to do this query, then you need the
email: String! @unique
in your schema
h
Let me try it. I resolved this issue by using this logic
const [user] = await ctx.db.query.users({ where: { email: email } },
{ id password }
)
a
Yes, using the
users
query allows you to use a non-unique field. However, the
user
query will require unique field(s). It was confusing to me at the start too 🙂
h
Copy code
Errors:

  User
    ✖ You are making a field unique, but there are already nodes that would violate that constraint.
Copy code
type User {
  id: ID! @unique
  email: String! @unique
  password: String!
  role: Role @default(value: "CANDIDATE")
}
a
Yes, I'm guessing multiple users have the same email.
h
Let me delete the data from my prisma service
a
But wait. What do you actually want to do? Do you want your user objects to have unique emails?
Or do you want them to be able to have non-unique emails and be able to search amongst them?
h
Yeah, Each user must have unique email
a
Then you can enforce that first
h
awesome! It is working now
Thanks
a
Glad to help 🙂