2
votes

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'"

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.

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)
        }
    }
}

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
          }
        }
      }
    `;

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);
}

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!

1

1 Answers

0
votes

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) {

Thanks though for the help!