You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS GraphQL删除报错:输入含DeleteNoteInput未定义字段

解决GraphQL删除mutation输入字段无效错误

问题原因

你的removeNote函数里,构造GraphQL请求变量时存在明显错误:variables: {input: {id}}中的id是未定义的变量,并没有从传入的note参数中获取实际的ID值。这种未定义的变量会被解析成不符合DeleteNoteInput类型要求的内容,直接触发报错。

修复代码

修改removeNote函数,从传入的note参数中正确提取id值:

async function removeNote(note){
  console.log(note)

  await client.graphql({
      query: deleteNoteMutation,
      variables: {input: {id: note.id}} // 明确使用note对象的id属性
  }).then(response => {
      console.log('Success! ', response)
  }).catch(error => {
      console.log('Failure Response: ', error)
  })
}

额外检查项

  • 确认控制台打印的note对象确实包含有效的id字段,避免传入空值或未定义的ID
  • Amplify根据你的Note模型生成的DeleteNoteInput仅需要id字段,不需要传入name、description等其他属性,只传id就符合类型要求

内容的提问来源于stack exchange,提问作者Stephen Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 14:57:21