【发布时间】: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