【问题标题】:ApolloError: GraphQL error: Validation error of type FieldUndefined: Field '<my query name>' in type 'Mutation' is undefined @ '<my query name'ApolloError:GraphQL 错误:FieldUndefined 类型的验证错误:字段 \'<my query name>\' in type \'Mutation\' is undefined @ \'<my query name\'
【发布时间】: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


    【解决方案1】:

    我使用了错误的 AppSync URL(例如,“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
    

    基本上,因为我没有从我的 amplify.graphql 文件部署我的 ApiKey 架构,所以 Amplify 没有生成相关的 AppSync 调用(即“createApiKey”)。因此,当我尝试使用我的 NodeJS 代码调用该调用时,AppSync 告诉我它未定义。

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 2020-07-13
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2018-09-18
      • 2018-08-04
      相关资源
      最近更新 更多