【问题标题】:Appsync 'Batch Create' Resolver gives "mapping template" errorAppsync“批量创建”解析器给出“映射模板”错误
【发布时间】:2019-09-01 16:43:48
【问题描述】:

我正在尝试为我创建的 BatchCreateIngredients 突变创建解析器,但是当我运行该突变时,我收到 MappingTemplate 类型的错误,我不知道为什么。

我的表名称是 IngredientsTable,我没有使用任何认知验证。

突变:

mutation batchCreateIngredient {
  batchCreateIngredients(
    input: [
    {name: "Cookie" vegan: VEGAN glutenfree: GLUTENFREE},
    {name: "Pizza", vegan: VEGAN, glutenfree: GLUTENFREE},
]) {
    items{
      id
      name
      vegan
    }
  }
}

错误信息:

{
  "data": {
    "batchCreateIngredients": null
  },
  "errors": [
    {
      "path": [
        "batchCreateIngredients"
      ],
      "data": null,
      "errorType": "MappingTemplate",
      "errorInfo": null,
      "locations": [
        {
          "line": 6,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Item list elements can't be null for table 'IngredientTable' at path '$[tables]'"
    }
  ]
}

我的架构的相关部分:

input CreateIngredientInput {
    name: String!
    vegan: Vegan!
    glutenfree: GlutenFree!
    popularity: Int
}

enum GlutenFree {
    GLUTENFREE
    CONTAINS_GLUTEN
    UNKNOWN
}

type Ingredient {
    name: String!
    id: ID!
    vegan: Vegan
    glutenfree: GlutenFree
    popularity: Int
}

type IngredientConnection {
    items: [Ingredient]
    nextToken: String
}

type Mutation {
    createIngredient(input: CreateIngredientInput!): Ingredient
    batchCreateIngredients(input: [CreateIngredientInput]): IngredientConnection
    updateIngredient(input: UpdateIngredientInput!): Ingredient
    deleteIngredient(input: DeleteIngredientInput!): Ingredient
}

enum Vegan {
    VEGAN
    NON_VEGAN
    UNKNOWN
}

BatchCreateIngredients 的解析器:

#set($ingdata = [])
#foreach($ing in ${ctx.args.input})
    $util.qr($ingdata.add($util.dynamodb.toMapValues($item)))
#end

{
    "version" : "2018-05-29",
    "operation" : "BatchPutItem",
    "tables" : {
        "IngredientTable": $utils.toJson($ingdata)
    }
}

【问题讨论】:

  • 你提到你的表名是IngredientsTable,但是你的映射模板有IngredientTable...错别字?

标签: amazon-dynamodb graphql velocity aws-appsync resolver


【解决方案1】:

你也过去了

{name: "Cookie" 素食主义者: VEGAN glutenfree: GLUTENFREE}

但映射

项目{ ID 姓名 素食主义者 }

glutenfree 缺失,解析器未处理 id

【讨论】:

    【解决方案2】:

    据我所知,问题似乎出在请求映射模板中。您调用了循环变量 $ing,但您将“$item”传递给 toMapValues 函数。可以试试把“item”改成“ing”吗?

    【讨论】:

      猜你喜欢
      • 2020-05-29
      • 2022-01-23
      • 2021-12-12
      • 2020-10-19
      • 2019-05-23
      • 2020-02-17
      • 2019-10-14
      • 2019-05-21
      • 1970-01-01
      相关资源
      最近更新 更多