【问题标题】:Calling AWS AppSync graphql API from Lambda从 Lambda 调用 AWS AppSync graphql API
【发布时间】:2020-09-10 23:56:36
【问题描述】:

我正在尝试使用 AWS-app sync graphql API 更新表的值, 我能够使用 lambda 中的 graphql 突变创建数据并将其添加到表中 但是当我尝试更新数据时它不起作用。 我从 API 网关调用这个 lambda 服务。

我指的是这篇文章的代码 https://cloudonaut.io/calling-appsync-graphql-from-lambda/

我想在云监视日志中提到 git no error

这是我的 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!
}

创建突变

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

更新突变

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;

【问题讨论】:

  • 你能澄清你的意思是“它不工作”吗?您是否收到任何错误、超时、拒绝访问……?
  • 我没有收到任何错误或任何消息,我可以从中找出为什么它没有更新表内的值,
  • 你检查过 cloudwatch 日志,看看你的 lambda 是否抛出任何错误?
  • @Marcin 这只是我的猜测可能是因为 graphql 中的 id 是 ID 类型,我正在传递字符串以进行值更新,我是 graphql 和 aws 的新手,所以不知道
  • 我猜你的客户端代码没有执行。由于您在 lambda 代码中使用 await,请参阅异步处理程序部分 - docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html

标签: amazon-web-services aws-lambda graphql aws-api-gateway aws-appsync


【解决方案1】:

感谢@cppgnlearner,您的猜测是正确的。

我刚刚从更新代码中删除了 .promise 它开始工作了。

不敢相信这么小的事情就花了我一整天的时间。

【讨论】:

    猜你喜欢
    • 2021-09-13
    • 2018-10-02
    • 2020-11-12
    • 2019-05-03
    • 2021-06-01
    • 2022-08-12
    • 2019-08-02
    • 2022-01-23
    • 2020-11-01
    相关资源
    最近更新 更多