我试图使用AppSync和aws-sdk
在NodeJS环境中运行一个简单的突变。我犯了个错误,但我想不出来。此查询在我的AppSync控制台中工作:
mutation MyMutation {
createApiKey(input: {key: "testconsole2"}) {
id
key
}
}
然后,当我在NodeJS中尝试它时,我无法让它工作(尽管我所有其他类似的查询都能工作):
async function createApiKey({ encryptedKey }: { encryptedKey: string }) {
const createApiKeyQueryString = `mutation createApiKey(
$key: String!,
){
createApiKey(
input: {
key: $key
}
){
key
}
}`;
try {
const runMutation = await appSyncClient.mutate({
mutation: gql(createApiKeyQueryString),
variables: {
key: encryptedKey,
},
});
console.log({
response: runMutation // Throws error before we reach here
});
return (runMutation as { data }).data;
} catch (error) {
console.log(error); // ApolloError: GraphQL error: Validation error of type FieldUndefined: Field 'createApiKey' in type 'Mutation' is undefined @ 'createApiKey
}
}
我犯了一个愚蠢的错误,但我不知道我做错了什么,或者错误信息意味着什么?
发布于 2022-11-21 07:07:44
我使用了错误的AppSync网址(例如,“https://.appsync-api.eu-west-2.amazonaws.com/graphql"”)。
这意味着我的ApiKey表的架构名称不存在,这就是下面试图告诉我的:
ApolloError: GraphQL error: Validation error of type FieldUndefined:
Field 'createApiKey' in type 'Mutation' is undefined @ 'createApiKey
基本上,因为我没有从我的ApiKey文件中部署我的amplify.graphql
模式,amplify.graphql
没有生成相关的AppSync调用(即'createApiKey')。因此,当我试图用我的NodeJS代码调用该调用时,AppSync告诉我它是未定义的。
https://stackoverflow.com/questions/74518845
复制