amplify-android icon indicating copy to clipboard operation
amplify-android copied to clipboard

AppSyncGraphQLRequestFactory.buildQuery build wrong query

Open lwang-79 opened this issue 2 years ago • 4 comments

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

GraphQL API

Gradle script dependencies

// Put output below this line


Environment information

# Put output below this line
implementation 'com.amplifyframework:core:1.36.1'
implementation 'com.amplifyframework:aws-auth-cognito:1.36.1'
implementation 'com.amplifyframework:aws-api:1.36.1'
implementation 'com.amplifyframework:aws-auth-cognito:1.36.1'

Please include any relevant guides or documentation you're referencing

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

Describe the bug

I tried to follow the tutorial, but I couldn't list the notes items.

After print the query result I found the following error message

'Validation error of type FieldUndefined: Field 'listNoteDatas' in type 'Query' is undefined @ 'listNoteDatas'', locations='[GraphQLLocation{line='2', column='3'}]', path='null', extensions='null'

Checked the query name in AppSync it's 'listNoteData' instead of 'listNoteDatas'.

So I think the Amplify Core and Amplify CLI use different name to build the query. Is there any workaround except manually change the schema in AppSync console?

Reproduction steps (if applicable)

Follow the tutorial, Create a NoteData schema, amplify codegen models Try to list the items

Code Snippet

    fun queryNotes() {
        Log.i(TAG, "Querying notes")

        Amplify.API.query(
            ModelQuery.list(NoteData::class.java),
            { response ->
                Log.i(TAG, "Queried")
                Log.i(TAG, response.toString())
                if (response.data != null) {
                    for (noteData in response.data) {
                        Log.i(TAG, noteData.name)
                        // TODO should add all the notes at once instead of one by one (each add triggers a UI refresh)
                        UserData.addNote(UserData.Note.from(noteData))
                    }
                }
            },
            { error -> Log.e(TAG, "Query failure", error) }
        )
    }

Log output

// Put your logs below this line
'Validation error of type FieldUndefined: Field 'listNoteDatas' in type 'Query' is undefined @ 'listNoteDatas'', locations='[GraphQLLocation{line='2', column='3'}]', path='null', extensions='null'

amplifyconfiguration.json

amplifyconfiguration.json.zip

GraphQL Schema

type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
    id: ID!
    name: String
    description: String
    image: String
}

Additional information and screenshots

No response

lwang-79 avatar Jul 08 '22 07:07 lwang-79

Hello, thank you for reaching out -- we generally advise using the Amplify docs instead of the AWS tutorial you linked to because it's out of date, but it seems like the behavior you are seeing is a bug. If you change the data type from NoteData to something else that doesn't end in Data, is the behavior resolved? The issue might be due to an inconsistent pluralization of Data.

tjleing avatar Jul 11 '22 17:07 tjleing

Yes, I have tested with some different nouns. Looks like the library add "s" for all names, but the CLI follows the grammar.

lwang-79 avatar Jul 12 '22 10:07 lwang-79

Hi @lwang-79 👋 we are currently working on improving pluralization in our codegen which should resolve this issue.

Please track the progress here: https://github.com/aws-amplify/amplify-codegen/pull/255

chrisbonifacio avatar Sep 14 '22 18:09 chrisbonifacio