我正在尝试为我创建的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)
}
}
答案 0 :(得分:0)
据我所知,问题似乎出在请求映射模板中。您已经调用了循环变量$ ing,但是您正在将“ $ item”传递给toMapValues函数。您可以尝试将“项目”更改为“ ing”吗?
答案 1 :(得分:0)
你也过去了
{name:“ Cookie”素食主义者:VEGAN不含麸质:不含麸质}
但是映射
项{ ID 名称 纯素 }
glutenfree丢失,并且解析器未处理ID