I've narrowed down to where the error is being thrown and it seems to be a Prisma
issue.
The error occurs here within the vote function:
const linkExists = await context.db.exists.Vote({
user: { id: userId },
link: { id: args.linkId }
})
I'm working my way through this tutorial .
I'm trying to "vote" for a post, but it throws the following error:
{
"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"
]
}
]
}
The mutation I'm sending is:
mutation{
vote(linkId:"cjit726cxfkpj0a21z74nuncu"){
id
}
}
Not exactly sure what this error means. I've been comparing my code to the official repo on Github , but I can't find the difference.
Here's my vote function:
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,
)
}
When I log out args
it shows:
query:
query ($_v0_where: VoteWhereInput) {
votes(where: $_v0_where) {
id
}
}
operationName: null
variables:
{
"_v0_where": {
"link": {
"id": "cjit5v46i2r3y0a21a7ez0t9p"
},
"user": {
"id": "cjis44x27gbn60a219abasvjz"
}
}
}
I've created a new user, created a post with that user (both work fine), but when I try to vote as that user I get stuck here.
My datamodel.schema
if you want:
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!
}
It is because the structure of db.exists
requires sending arguments wrapped in a where
field.
Looks like that docs are outdated, will get them updated as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.