アップデート
エラーがスローされている場所に絞り込みましたが、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の公式リポジトリと比較してきましたが、違いがわかりません。
ここに私の投票機能があります:
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!
}