【问题标题】:AppSync/Amplify Query using a Parameter Error ""Validation error of type FieldUndefined:"AppSync/Amplify Query using a Parameter Error ""FieldUndefined 类型的验证错误:"
【发布时间】:2020-07-13 18:09:04
【问题描述】:

我目前有一个 AppSync 架构,在其中我在 AppSync 控制台中创建了一个单独的查询,以便保留某些参数 (assetId) 并在我的 DynamoDB 表中获取结果列表。我已经在 AppSync 控制台中测试了查询,它工作正常,我现在只是在我的 React 应用程序中使用 Amplify 来调用查询时遇到了麻烦。运行我的应用程序时出现以下错误:

DisplayCard.js:34 Uncaught (in promise) {data: null, errors: Array(1)}
"Validation error of type FieldUndefined: Field 'getAssetIdRating' in type 'Query' is undefined @ 'getAssetIdRating'"

我已尝试按照 Amplify 网站 (https://aws-amplify.github.io/docs/js/api) 遵循文档,但仍然收到此错误。

这里是我在 AppSync 控制台中运行时的查询供参考:(返回所需的结果)

    query getAssetIdRating {
      getRatingsAssetId(assetId:"949142fb-91d2-41bd-8c04-1d42ed8166c9") {
        items {
          id
          assetId
          rating
        }
      }
    }

我用于此查询的解析器如下:(我创建了一个单独的索引)

{
    "version" : "2017-02-28",
    "operation" : "Query",
    "index": "assetId-index",
    "query" : {
        ## Provide a query expression. **
        "expression": "assetId = :assetId",
        "expressionValues" : {
            ":assetId" : $util.dynamodb.toDynamoDBJson($ctx.args.assetId)
        }
    }
}

现在转到我的 React 代码,这是我在 react 中使用的当前查询,位于 src/graphql/queries 下。

    export const getAssetIdRating = /* GraphQL */ `
      query getRatingAssetId($assetId: ID) {
        getAssetIdRating(assetId: $assetId) {
          items {
            id
            assetId
            rating
          }
        }
      }
    `;

当我在我的 React 应用程序中调用它时:

componentDidMount = async () => {
    this.getRatings();
}

getRatings = async () => {
    let { assetIdRatings } = this.state;
    const result = await API.graphql(graphqlOperation(queries.getAssetIdRating, {assetId: '949142fb-91d2-41bd-8c04-1d42ed8166c9'}));
    console.log(result);
}

请注意,当我调用 listRatings 查询时,它工作正常,只是不适用于此查询。附带说明一下,我稍后通过 AppSync 控制台手动添加了此查询,我认为这不会有问题吗?

无论哪种方式,任何帮助都将不胜感激!如果需要,我可以上传更多必要的代码!感谢您的帮助!

【问题讨论】:

    标签: reactjs graphql aws-amplify aws-appsync


    【解决方案1】:

    对不起,你可以忽略这个问题,这是一个简单的打字错误:P 你在深夜错过它!

    您可以在我的查询中看到输入错误:

    getRatingsAssetId(assetId:"949142fb-91d2-41bd-8c04-1d42ed8166c9") {
    
    getAssetIdRating(assetId: $assetId) {
    

    感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 2022-11-21
      • 2021-10-20
      • 2018-08-04
      • 1970-01-01
      • 2019-12-04
      • 2020-11-23
      • 1970-01-01
      • 2023-03-12
      • 2021-11-30
      相关资源
      最近更新 更多