我具有以下解析程序设置:
#set($questions = [])
#foreach($item in ${ctx.args.questions})
#set($item.id = $util.dynamodb.toDynamoDBJson($util.autoId()))
$util.qr($questions.add($util.dynamodb.toMapValues($item)))
#end
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables" : {
"QuestionTable": $utils.toJson($questions)
}
}
以及以下GraphQL模式:
input CreateQuestionInput {
text: String
sectionId: ID!
}
input CreateScoreInput {
score: Int!
questionId: ID!
userId: ID!
}
input CreateSectionInput {
title: String
subSection: String
}
input DeleteQuestionInput {
id: ID!
}
input DeleteScoreInput {
id: ID!
}
input DeleteSectionInput {
id: ID!
}
type Mutation {
...
createQuestion(input: CreateQuestionInput!): Question
batchCreateQuestion(questions: [CreateQuestionInput]!): [Question]
}
type Query {
getSection(id: ID!): Section
listSections(filter: TableSectionFilterInput, limit: Int, nextToken: String): SectionConnection
getScore(id: ID!): Score
listScores(filter: TableScoreFilterInput, limit: Int, nextToken: String): ScoreConnection
getQuestion(id: ID!): Question
listQuestions(filter: TableQuestionFilterInput, limit: Int, nextToken: String): QuestionConnection
}
type Question {
id: ID!
text: String
sectionId: ID!
}
type QuestionConnection {
items: [Question]
nextToken: String
}
type Schema {
query: Query
}
type Score {
id: ID!
score: Int!
questionId: ID!
userId: ID!
}
type ScoreConnection {
items: [Score]
nextToken: String
}
type Section {
id: ID!
title: String
subSection: String
questions: [Question]
}
type SectionConnection {
items: [Section]
nextToken: String
}
input TableQuestionFilterInput {
id: TableIDFilterInput
text: TableStringFilterInput
sectionId: TableIDFilterInput
}
input UpdateQuestionInput {
id: ID!
text: String
sectionId: ID
}
(我已经编辑了一些架构,因为它相当大)。
当我尝试运行查询时:
mutation BatchCreateQuestions($sec: ID!) {
batchCreateQuestion(questions: [
{
text: "Tester 1"
sectionId: $sec
},
{
text: "Tester 2",
sectionId: $sec
}
]) {
id
text
sectionId
}
}
带有变量:
{ "sec": "abc123" }
我得到答复:
{
"data": {
"batchCreateQuestion": [
null,
null
]
}
}
当我检查DynamoDB表时,它没有保存值。我已经为该数据源授予了完全的dynamodb权限,但仍然没有任何乐趣。
答案 0 :(得分:1)
结果是,我授予了对类似名称角色的批量写入权限,而不是影响该数据源的角色。如果您看到类似的问题,请检查您的IAM角色/权限。傻我
答案 1 :(得分:0)
您的响应模板在解析器中是什么样的?基于上面的表名称为$util.toJson($ctx.result.data.QuestionTable)
,它应该为QuestionTable
,因为它会自动转换为响应上下文。