【发布时间】:2019-05-12 09:27:28
【问题描述】:
当将此查询运行到 Amplify 控制台时,效果很好 - 所以我假设架构和数据库设置正确:
mutation CreateUser {
createUser(input: {
name: "Nader Dabit"
email: "naderdabit@site.com"
image: "someimagepath"
mobile: 122122
}) {
id
name
email
image
mobile
}
}
在我的 RN 应用程序中,我以以下方式配置了 AWS Amplify(但我不确定这是否应该是这样,但登录/注册等过程似乎工作正常):
Amplify.configure({Auth: apiKeyStore, aws_appsync_graphqlEndpoint: "https://xxx.appsync-api.ap-xxx-1.amazonaws.com/graphql",
aws_appsync_region: "ap-xxx-1", aws_appsync_authenticationType: "API_KEY", aws_appsync_apiKey: "da2-xxxx"});
因此我有以下代码来调用 mutation 方法:
const CreateUser = `mutation CreateUser(
$name: String!,
$email: String!,
$mobile: Int!,
$image: String!
) {
createUser(name:$name, email:$email, mobile:$mobile, image:$image)
{
id
name
email
mobile
image
}
}`;
// inside a method
try
{
const newUser = await API.graphql(graphqlOperation(CreateUser, {name: name, email: email, mobile: mobile, image: image}));
console.log('newUserIncoming: ', newUser);
}
catch (err)
{
console.log('error while create user: ', err);
}
但上面的调用总是转向错误/捕获,并带有以下错误对象(如 React Native Debugger 所示):
【问题讨论】:
标签: react-native amazon-dynamodb graphql aws-appsync aws-amplify