【问题标题】:"Variable '$data' expected value of type 'VoteCreateInput"“'VoteCreateInput'类型的变量'$data'预期值”
【发布时间】:2020-02-07 11:11:31
【问题描述】:

当我尝试进行“投票”突变时,出现以下错误。我的其他突变工作正常。 当我尝试进行“投票”突变时,出现以下错误。我的其他突变工作正常。 当我尝试进行“投票”突变时,出现以下错误。我的其他突变工作正常。

"data": null,
"errors": [
{
  "message": "Variable '$data' expected value of type 'VoteCreateInput!' but 
 got: {\"user\":{\"connect\": 
 {\"id\":\"ck1j3nzi68oef090830r8wd6b\"}},\"link\":{\"connect\": 
 {\"id\":\"ck1j58loj8x570908njwe4eu7\"}}}. Reason: 'User' Expected non-null 
  value, found null. (line 1, column 11):\nmutation ($data: 
  VoteCreateInput!) {\n          ^",
  "locations": [
    {
      "line": 2,
      "column": 3
    }
  ],
  "path": [
    "vote"
  ]
 }
]

变异

async function vote(parent, args, context, info) {
// 1
const userId = getUserId(context)

// 2
const linkExists = await context.prisma.$exists.vote({
  user: { id: userId },
  link: { id: args.linkId },
})

if (linkExists) {
  throw new Error(`Already voted for link: ${args.linkId}`)
}

// 3
return context.prisma.createVote({
  user: { connect: { id: userId } },
  link: { connect: { id: args.linkId } },
})

}

datamodel.schema

type Link {
id: ID! @id
createdAt: DateTime! @createdAt
description: String!
url: String!
postedBy: User
votes: [Vote!]!
}

type User {
id: ID! @id
name: String!
email: String @unique
password: String!
links: [Link!]!
votes: [Vote!]!
}

type Vote {
id: ID! @id
link: Link!
user: User!
}

schema.graphql

type Mutation {
vote(linkId: ID!): Vote!
}

type Link {
id: ID!
description: String!
url: String!
postedBy: User
votes: [Vote!]!
}

【问题讨论】:

  • 您是否尝试传递整个用户对象而不是 userid
  • @merko 是的。但没有运气!但如果我从“投票”类型中删除用户,它会起作用。我不知道为什么它不能使用上述架构。

标签: graphql prisma


【解决方案1】:

prisma 数据库中有一个故障,它没有随着数据模型的变化而更新。 我已经创建了一个新的数据库实例,现在它工作正常。

【讨论】:

    猜你喜欢
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    相关资源
    最近更新 更多