javascript - GraphQL 突变抛出错误
问题描述
更新
我已经缩小到引发错误的位置,这似乎是一个Prisma
问题。
错误发生在投票功能中:
const linkExists = await context.db.exists.Vote({
user: { id: userId },
link: { id: args.linkId }
})
原来的
我正在学习本教程。
我正在尝试为帖子“投票”,但会引发以下错误:
{
"data": {
"vote": null
},
"errors": [
{
"message": "Variable '$_v0_where' cannot be non input type 'VoteWhereInput'.
(line 1, column 20):\nquery ($_v0_where: VoteWhereInput)
{\n ^",
"locations": [],
"path": [
"votes"
]
}
]
}
我发送的突变是:
mutation{
vote(linkId:"cjit726cxfkpj0a21z74nuncu"){
id
}
}
不完全确定此错误的含义。我一直在将我的代码与Github 上的官方 repo进行比较,但我找不到区别。
这是我的投票功能:
async function vote(parent, args, context, info) {
const userId = getUserId(context)
const linkExists = await context.db.exists.Vote({
user: { id: userId },
link: { id: args.linkId },
})
if (linkExists) {
throw new Error(`Already voted for link: ${args.linkId}`)
}
return context.db.mutation.createVote(
{
data: {
user: { connect: { id: userId } },
link: { connect: { id: args.linkId } },
},
},
info,
)
}
当我注销时,args
它显示:
query:
query ($_v0_where: VoteWhereInput) {
votes(where: $_v0_where) {
id
}
}
operationName: null
variables:
{
"_v0_where": {
"link": {
"id": "cjit5v46i2r3y0a21a7ez0t9p"
},
"user": {
"id": "cjis44x27gbn60a219abasvjz"
}
}
}
我创建了一个新用户,与该用户创建了一个帖子(两者都工作正常),但是当我尝试以该用户的身份投票时,我被困在这里。
datamodel.schema
如果你愿意,我的:
type Link {
id: ID! @unique
description: String!
url: String!
postedBy: User
votes: [Vote!]!
}
type User {
id: ID! @unique
name: String!
email: String! @unique
password: String!
links: [Link!]!
votes: [Vote!]!
}
type Vote {
id: ID! @unique
link: Link!
user: User!
}
解决方案
这是因为 的结构db.exists
需要发送包装在where
字段中的参数。
看起来文档已经过时,也会更新它们。
推荐阅读
- c# - 不可见的DataGridView行在TabControl的几个TabPages中可见
- chart.js - 是否可以为 Chart.js 中的每个数据集设置刻度步长?
- html - 如何创建一侧高于另一侧的行
- node.js - 将所有其他请求重定向到索引页面
- c++11 - 如何使用 SFINAE 启用转换运算符的显式隐性?
- python - terraform 输出文件没有状态选项
- docker - 是否可以在 Dockerfile 中获取 docker 引擎的架构?
- eclipse - 不想解决 Maven Java EE 配置问题
- sql - 在计算中排除周末
- amazon-web-services - AWS 环境中 Informatica BDM 的调度程序