【问题标题】:Appsync custom resolver error "Unable to transform Response Template"Appsync 自定义解析程序错误“无法转换响应模板”
【发布时间】:2021-11-04 17:53:18
【问题描述】:

我正在尝试编写“BatchPutItem”自定义解析器,以便可以创建多个项目(一次不超过 25 个),这些项目应该接受参数列表,然后执行批处理操作。 这是我在 CusomtResolver 中的代码:

#set($pdata = [])
#foreach($item in ${ctx.args.input})
    $util.qr($item.put("createdAt", $util.time.nowISO8601()))
    $util.qr($item.put("updatedAt", $util.time.nowISO8601()))
    $util.qr($item.put("__typename", "UserNF"))
    $util.qr($item.put("id", $util.defaultIfNullOrBlank($item.id, $util.autoId())))
    $util.qr($pdata.add($util.dynamodb.toMapValues($item)))
#end

{
    "version" : "2018-05-29",
    "operation" : "BatchPutItem",
    "tables" : {
        "Usertable1-staging": $utils.toJson($pdata)
    }
}

查询控制台部分的响应:

{
  "data": {
    "createBatchUNF": null
  },
  "errors": [
    {
      "path": [
        "createBatchUserNewsFeed"
      ],
      "data": null,
      "errorType": "MappingTemplate",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Unsupported operation 'BatchPutItem'. Datasource Versioning only supports the following operations (TransactGetItems,PutItem,BatchGetItem,Scan,Query,GetItem,DeleteItem,UpdateItem,Sync)"
    }
  ]
}

查询是:

mutation MyMutation {
  createBatchUNF(input: [{seen: false, userNFUserId: "userID", userNFPId: "pID", user NFPOwnerId: "ownerID"}]) {
    items {     
      id
      seen
    }
  }
}

冲突检测也被关闭

当我检查云日志时,我发现了这个错误:

【问题讨论】:

    标签: amazon-web-services aws-amplify aws-appsync vtl


    【解决方案1】:

    我可以通过禁用DataStore for entire API 来解决这个问题。 当我们使用放大控制台创建一个新的项目/后端应用程序时,在数据选项卡中它要求我们启用数据存储,以便我们可以开始对我们的 GraphQL api 进行建模,这就是启用整个 API 的版本控制的原因,它会阻止 batchWrite 到执行。 所以为了解决这个问题,我们可以按照以下步骤进行: [注意:我使用的是@aws-amplify/cli]

    $ amplify update api
    ? Please select from one of the below mentioned services: GraphQL
    ? Select from the options below: Disable DataStore for entire API
    
    

    然后amplify push 这将解决此问题。

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 2021-12-13
      • 2014-04-16
      • 1970-01-01
      • 2011-04-24
      • 2023-03-20
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多