amplify api, Validation error of type FieldUndefined: Field 'listNoteDatas' in type 'Query' is undefined @ 'listNoteDatas''

Viewed 2039

** It's written using a program of translator. **

https://aws.amazon.com/getting-started/hands-on/build-android-app-amplify/module-four/?nc1=h_ls

I coded as above.

In the case of create, it was performed normally, and it was possible to check the data in DynamoDB in the AWS account. However, in the case of read, an error message of "Validation error of type FieldUndefined: Field 'listNoteDatas' in type 'Query' is undefined @ 'listNoteDatas'' is returned.

Amplify.API.query(
            ModelQuery.list(NoteData::class.java),
            { response ->
                Log.i(TAG, "Queried 1")

                for (noteData in response.data) {
                        Log.i(TAG, noteData.name)
                        UserData.addNote(UserData.Note.from(noteData))
                    }
            },
            { error -> Log.e(TAG, "Query failure", error) }
        )

By designating the id with the get function instead of the list, it was performed normally when reading.

Amplify.API.query(
            ModelQuery.get(NoteData::class.java, "id value checked in DynamoDB"),
            { response ->
                Log.i(TAG, "Queried 2")

                if (response.data != null){
                    UserData.addNote(UserData.Note.from(response.data))
                } else {
                    Log.e(TAG, "response.data != null")
                }
            },
            { error -> Log.e(TAG, "Query failure", error) }
        )

How to run ModelQuery.list normally?

** It's written using a program of translator. **

2 Answers

Edit scheme to change to listNoteDatas and connect to DB.NoteData table to work normally.

  1. first you need to change schema

In AWS AppSync > Yours > Schema

find type Query {...} in left side and change listNoteData(filter...) to listNoteDatas(filter...)

click save schema button on top right

enter image description here

  1. setting resolver at listNoteDatas

scroll down find Query section in Resolvers in right side

click connect button on listNoteDatas, select NoteDataTable for resolver table, in Configure mapping templates in order select List items for first, select Return single item for second

and save resolver

enter image description here

  1. build run, no error

enter image description here

Good!

Related