我正在使用 React JS 应用程序通过 AWS AppSync 客户端和 GraphQL API 将数据提交到云中的 NoSQL 表。我使用 AWS Amplify 自动生成了 GraphQL 操作,现在我尝试在我的 React 代码中提交以下操作:(注意和公司只是在 React 的状态下保存的字符串值)
createOffer(note, company) {
const input = {
place: company,
title_de: note,
category: "product",
}
return API.graphql(graphqlOperation(mutations.createOffers, {input: input
}));
这会产生一个异常“[object Object]”
现在,如果我像这样直接传递字符串
createOffer() {
const input = {
place: "Example Company ",
title_de: "Example Title",
category: "product",
}
return API.graphql(graphqlOperation(mutations.createOffers, {input: input
}));
它工作正常。到目前为止,我发现的唯一解决方法是将保存字符串值的变量包装在 JSON.stringify(company) 和 JSON.stringify(note) 中。但是相应的数据库条目用双引号“Example Company”而不是Example Company 括起来。
我想避免手动修改自动生成的 GraphQL API 代码,因为我希望它会经常更改。
客户端是否有一个选项可以将实际字符串从 React 状态获取到 API 调用中,而不需要 GraphQL 将其识别为对象或在数据库中以双引号结尾?