2
votes

I have the following resolver settings:

#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)
    }
}

And the following GraphQL schema:

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
}

(I've redacted some of the schema as it was fairly large).

When I attempt to run the query:

mutation BatchCreateQuestions($sec: ID!) {
  batchCreateQuestion(questions: [
    {
      text: "Tester 1"
      sectionId: $sec
    },
    {
      text: "Tester 2",
      sectionId: $sec
    }
  ]) {
    id
    text
    sectionId
  }
}

With the variables:

{ "sec": "abc123" }

I get the response:

{
"data": {
    "batchCreateQuestion": [
      null,
      null
    ]
  }
}

And when I check the DynamoDB table, it hasn't saved the values. I've granted full dynamodb permissions for this datasource, but still no joy.

2
What is the final answer of it? I am stuck - Vikramsinh Gaikwad

2 Answers

2
votes

Turns out I'd given batch write permissions to a similarly named role instead of the role affecting this data source. If you see a similar issue, check your IAM roles/permissions. Silly me.

0
votes

What does your response template look like in the resolver? It should be $util.toJson($ctx.result.data.QuestionTable) based on the above table name being QuestionTable as that gets automatically translated into the response context.