Haider Malik
07/18/2018, 7:48 AMschema.graphql
type User {
id: ID! @unique
email: String!
password: String!
role: Role @default(value: "CANDIDATE")
}
prisma.graphql
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
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
{
"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?Arnab
07/18/2018, 8:06 AMemail
is not unique
and if you look at input type for UserWhereUniqueInput
, you need some unique key 🙂email: String! @unique
in your schemaHaider Malik
07/18/2018, 8:08 AMconst [user] = await ctx.db.query.users({ where: { email: email } },
{ id password } )
Arnab
07/18/2018, 8:09 AMusers
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 🙂Haider Malik
07/18/2018, 8:09 AMErrors:
User
✖ You are making a field unique, but there are already nodes that would violate that constraint.
type User {
id: ID! @unique
email: String! @unique
password: String!
role: Role @default(value: "CANDIDATE")
}
Arnab
07/18/2018, 8:10 AMHaider Malik
07/18/2018, 8:10 AMArnab
07/18/2018, 8:10 AMHaider Malik
07/18/2018, 8:11 AMArnab
07/18/2018, 8:11 AMHaider Malik
07/18/2018, 8:14 AMArnab
07/18/2018, 8:14 AM