使用参数错误“"类型为FieldUndefined的验证错误的AppSync/放大查询“; [英] AppSync/Amplify Query using a Parameter Error ""Validation error of type FieldUndefined:"

查看:305
本文介绍了使用参数错误“"类型为FieldUndefined的验证错误的AppSync/放大查询“;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I currently have a AppSync schema where I created a separate query within the AppSync console in order retain certain parameter (assetId) and get a list of the results in my DynamoDB table. I have tested the query already within the AppSync console and it works fine, I am now just having troubles using Amplify in my React App in order to call the query. I get the following error when running my App:

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 ),但仍收到此错误.

I have tried following the documentation as per the Amplify site (https://aws-amplify.github.io/docs/js/api) but am still receiving this error.

作为参考,以下是我在AppSync控制台中运行查询时的查询:(返回所需结果)

For reference here is the query when I run it in the AppSync console: (returns the desired result)

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

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

The resolver that I am using for this query is the following: (I have created a separate Index)

{
    "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下.

And now moving onto my React code, this is the current query that I am using within react, under src/graphql/queries.

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

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

And when I call it then in my React application:

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控制台手动添加了此查询,我不认为这会引起问题吗?

Note that when I call the listRatings query it works fine, just does not work with this query. And as a side note, I added this query later in manually through the AppSync console, I don't presume that should play an issue?

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

Either way, any help would be greatly appreciated! And I can upload anymore necessary code if required! Thanks for the help!

推荐答案

抱歉,您可以忽略该问题,这是一个简单的键入错误:P您会在深夜错过它!

sorry you can ignore the question, it was a simple typing error :P You miss it when its late at night!

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

You can see the typing error on my Query:

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

getAssetIdRating(assetId: $assetId) {

感谢您的帮助!

这篇关于使用参数错误“"类型为FieldUndefined的验证错误的AppSync/放大查询“;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆