gpt4 book ai didi

javascript - GraphQL 突变抛出错误

转载 作者:行者123 更新时间:2023-12-01 01:56:18 26 4
gpt4 key购买 nike

更新

我已将范围缩小到引发错误的位置,这似乎是 Prisma 问题。

投票函数中发生错误:

const linkExists = await context.db.exists.Vote({
user: { id: userId },
link: { id: args.linkId }
})

原始

我正在努力解决this tutorial .

我尝试为某个帖子“投票”,但它抛出以下错误:

{
"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
}
}

不太清楚这个错误的含义。我一直在将我的代码与 official repo on Github 进行比较,但我找不到区别。

这是我的投票功能:

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 字段中的参数。

enter image description here看起来该文档已过时,将得到 them updated以及。

关于javascript - GraphQL 突变抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51013126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com