Reputation: 1165
I've been testing GraphQL for a few days now and I'm doing the authentication management (by following this tutorial). I'm currently blocked with the following error:
Unknown arg `email` in where.email for type UserWhereUniqueInput. Did you mean `id`?
When I make the following request:
mutation {
login(email: "[email protected]", password: "Test123") {
token
user {
email
links {
url
description
}
}
}
}
Here's my login resolver:
let login = async (parent, args, context, info) => {
const user = await context.prisma.user.findUnique({
where: {
email: args.email
}
});
if (!user)
throw new Error('No such user found');
const valid = await bcrypt.compare(args.password, user.password);
if (!valid)
throw new Error('Invalid password');
const token = jwt.sign({ userId: user.id }, APP_SECRET);
return {
token,
user
}
}
And my GraphQL schema:
type Mutation {
post(url: String!, description: String!): Link!
updateLink(id: Int!, url: String, description: String): Link
deleteLink(id: Int!): Link
signup(email: String!, password: String!, name: String!): AuthPayload
login(email: String!, password: String!): AuthPayload
}
I don't really see where it could get in the way...
Upvotes: 3
Views: 5876
Reputation: 1165
Okay so after a long investigation, I've found the solution. The problem didn't come from GraphQL but from Prisma. To add an email field to the User model, we need to define it the @unique directive like this:
model User {
id Int @id @default(autoincrement())
name String
email String @unique
password String
links Link[]
}
Solution was initially posted here: https://github.com/howtographql/howtographql/issues/661#issuecomment-401372966
Upvotes: 9