graphql error: mutation with where not working
graphql error: mutation with where not working
我正在使用 Prisma GraphqQL,但由于 where 选择器的突变而出现此错误:
"You provided an invalid argument for the where selector on User"
突变:
mutation UpdateUserMutation($data: UserUpdateInput!, $where: UserWhereUniqueInput!) {
updateUser(data: $data, where: $where) {
id
name
email
role
}
}
变量:
{
"data": {
"name": "alan", "email": "alan@gmail.com", "role": "ADMIN"
},
"where": {
"id": "cjfsvcaaf00an08162sacx43i"
}
}
结果:
{
"data": {
"updateUser": null
},
"errors": [
{
"message": "You provided an invalid argument for the where selector on User.",
"locations": [],
"path": [
"updateUser"
],
"code": 3040,
"requestId": "api:api:cjftyj8ov00gi0816o4vvgpm5"
}
]
}
架构:
updateUser(
data: UserUpdateInput!
where: UserWhereUniqueInput!
): User
type UserWhereUniqueInput {
id: ID
resetPasswordToken: String
email: String
}
为什么这个突变不起作用?
有颜色:
突变 GraphQL
模式 Graphql
额外信息
这个项目的完整代码是here:
Graphql playground 是 here:
控制台视图(变量为空):
查询用户(ID:cjfsvcaaf00an08162sacx43i)。因此可以在查询中使用 "where" 运算符找到用户,但不能在突变中找到。
您的 updateUser 解析器未正确实现:
async function updateUser(parent, { id, name, email, role }, ctx, info) {
// console.log( id, name, email)
await ctx.db.mutation.updateUser({
where: { id: id },
data: {name: name, email: email, role: role},
})
}
你的突变有数据和位置两个参数,但你期望参数列表 { id, name, email, role }。
相应地更新您的架构或解析器。
我正在使用 Prisma GraphqQL,但由于 where 选择器的突变而出现此错误: "You provided an invalid argument for the where selector on User"
突变:
mutation UpdateUserMutation($data: UserUpdateInput!, $where: UserWhereUniqueInput!) {
updateUser(data: $data, where: $where) {
id
name
email
role
}
}
变量:
{
"data": {
"name": "alan", "email": "alan@gmail.com", "role": "ADMIN"
},
"where": {
"id": "cjfsvcaaf00an08162sacx43i"
}
}
结果:
{
"data": {
"updateUser": null
},
"errors": [
{
"message": "You provided an invalid argument for the where selector on User.",
"locations": [],
"path": [
"updateUser"
],
"code": 3040,
"requestId": "api:api:cjftyj8ov00gi0816o4vvgpm5"
}
]
}
架构:
updateUser(
data: UserUpdateInput!
where: UserWhereUniqueInput!
): User
type UserWhereUniqueInput {
id: ID
resetPasswordToken: String
email: String
}
为什么这个突变不起作用?
有颜色:
突变 GraphQL
额外信息
这个项目的完整代码是here:
Graphql playground 是 here:
控制台视图(变量为空):
查询用户(ID:cjfsvcaaf00an08162sacx43i)。因此可以在查询中使用 "where" 运算符找到用户,但不能在突变中找到。
您的 updateUser 解析器未正确实现:
async function updateUser(parent, { id, name, email, role }, ctx, info) {
// console.log( id, name, email)
await ctx.db.mutation.updateUser({
where: { id: id },
data: {name: name, email: email, role: role},
})
}
你的突变有数据和位置两个参数,但你期望参数列表 { id, name, email, role }。
相应地更新您的架构或解析器。