0

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;
Aditya toke
  • 461
  • 4
  • 14
  • 1
    Can you clarify what you mean that "its not working"? Do you get any errors, timeouts, access denies, ...? – Marcin May 24 '20 at 09:32
  • I dont get any error nor any message from which I can find out why its not updating the value inside table, – Aditya toke May 24 '20 at 09:40
  • Have you checked cloudwatch logs, to see if your lambda throws any errors? – Marcin May 24 '20 at 09:41
  • @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 May 24 '20 at 09:42
  • @marcin yes I checked my cloudwatch logs for error I put console and try catch block on each line to find out the error but got no success – Aditya toke May 24 '20 at 09:42
  • @Marcin any solution ? – Aditya toke May 24 '20 at 12:23
  • Sorry, do not know at present. – Marcin May 24 '20 at 12:28
  • 1
    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 - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html, – hangc May 24 '20 at 13:22
  • @cppgnlearner Thanks bro your suggestion at least provided me with an error on which I can check – Aditya toke May 24 '20 at 14:01

1 Answers1

0

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.

Aditya toke
  • 461
  • 4
  • 14