【发布时间】:2022-11-21 23:07:44
【问题描述】:
我正在尝试在 NodeJS 环境中使用带有 aws-sdk 的 AppSync 运行一个简单的突变。我犯了一个错误,但我无法弄清楚。此查询适用于我的 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
}
}
我犯了一个愚蠢的错误,但我无法弄清楚我做错了什么,或者错误消息是什么意思?
【问题讨论】:
标签: node.js graphql aws-sdk aws-amplify aws-appsync