【问题标题】:GraphQL mutation throwing errorGraphQL 突变抛出错误
【发布时间】:2018-12-03 10:02:30
【问题描述】:

更新

我已将范围缩小到引发错误的位置,这似乎是 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!
}

【问题讨论】:

    标签: javascript graphql prisma prisma-graphql


    【解决方案1】:

    这是因为db.exists 的结构需要发送包装在where 字段中的参数。

    看起来文档已经过时了,也会得到them updated

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 1970-01-01
      • 2019-11-02
      • 2021-09-23
      • 2018-01-06
      • 2016-10-18
      • 1970-01-01
      • 2017-07-13
      • 2023-02-11
      相关资源
      最近更新 更多