0
votes

I am trying to update the value of a table using the AWS-app sync graphql API, I am able to create data and add it in a table using graphql mutation in lambda but when I am trying to update the data its not working. I am calling this lambda service from an API Gateway.

I am referring this article to code https://cloudonaut.io/calling-appsync-graphql-from-lambda/

I would like to mentioned git no error in cloud watch log

Here is the schema for my graphql

type Mutation {
createLib_content(input: CreateLib_contentInput!): lib_content
    @aws_iam
updateLib_content(input: UpdateLib_contentInput!): lib_content
    @aws_iam
deleteLib_content(input: DeleteLib_contentInput!): lib_content
}

input CreateLib_contentInput {
content: String
userId: String
}

input UpdateLib_contentInput {
content: String
id: ID!
}

Create Mutation

      graphqlData = await clientDetails.mutate({
    mutation: gql(`
   mutation CreateLibContent($input: CreateLib_contentInput!) {
              createLib_content(input: $input) {
                                      id
                                      content
                                               }
    }`),
    variables: {
      input: {
          content : {},
          userId : identitiesDetails.userId
      }
    },
  });

Update Mutation

const mutation = gql(`
   mutation UpdateLibContent($input: UpdateLib_contentInput!) {
updateLib_content(input: $input) {
  userId
  content
}
 }`);
  await clientDetails.mutate({
       mutation,
       variables: {
             input: {
                     id : "2947c37e-6f76-40d8-8c10-4cd6190d3597",
                     content : JSON.stringify(event)
                    }
                  }
  }).promise;
1
Can you clarify what you mean that "its not working"? Do you get any errors, timeouts, access denies, ...? - Marcin
I dont get any error nor any message from which I can find out why its not updating the value inside table, - Aditya toke
Have you checked cloudwatch logs, to see if your lambda throws any errors? - Marcin
@Marcin Its just my guess may be because id in graphql is of type ID and I am passing string for value updation, I am new to graphql and aws so no idea about it - Aditya toke
My Guess is that your client code does not execute. Since you are using await in your lambda code, please refer to the async handlers section - docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html, - hangc

1 Answers

0
votes

Thanks to @cppgnlearner your guess were right.

I just removed the .promise from my update code And it started working.

can't believe such a small thing took my whole day.