javascript - Unknown arg `email` in where.email for type UserWhereUniqueInput. GraphQL | NodeJS
问题描述
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: "contact@floriankamps.fr", 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...
解决方案
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
推荐阅读
- python - Airflow HttpSensor 使用默认主机
- python - 在 Django 中使用 Markdown2
- wordpress - WooCommerce 错误:我们无法处理您的订单,请重试
- python - 下载时如何从请求中获取媒体类型?
- python - 将值添加为字典中的列表元素
- java - Jackson JsonRootName 不添加任何根值
- python - 'import' 未被识别为内部或外部命令
- python - 我在 Eratosthenes 筛上的代码有问题
- python - 基于python中的字节范围可视化文件
- fortran - 子程序中二维数组的初始化