Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppSyncGraphQLRequestFactory.buildQuery build wrong query #1814

Open
1 task done
lwang-79 opened this issue Jul 8, 2022 · 4 comments
Open
1 task done

AppSyncGraphQLRequestFactory.buildQuery build wrong query #1814

lwang-79 opened this issue Jul 8, 2022 · 4 comments
Labels
api bug Something isn't working GraphQL API Related to the API (GraphQL) category/plugins

Comments

@lwang-79
Copy link

lwang-79 commented Jul 8, 2022

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

@tjleing tjleing added bug Something isn't working GraphQL API Related to the API (GraphQL) category/plugins labels Jul 11, 2022
@tjleing
Copy link
Contributor

tjleing commented Jul 11, 2022

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.

@lwang-79
Copy link
Author

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

@chrisbonifacio
Copy link
Member

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

Please track the progress here: aws-amplify/amplify-codegen#255

@mattcreaser mattcreaser removed the p2 label Jul 25, 2023
@lawmicha
Copy link
Member

lawmicha commented Jul 2, 2024

The aws-amplify/amplify-codegen#255 PR has been closed but I don't think the Android changes have been merged in. I can see in one of the codegen java tests that it's still got pluralName instead of splitting it into the two list and sync plural names (https://github.com/aws-amplify/amplify-codegen/blob/main/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap#L26).

The next steps is to apply the codegen changes, use the closed PR as reference and Swift codegen PR as reference aws-amplify/amplify-codegen#667

@lwang-79 if you are still experience pluralname mismatch, one workaround is to use a different model name that does get plurailzed with s such as Note instead of NoteData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api bug Something isn't working GraphQL API Related to the API (GraphQL) category/plugins
Projects
None yet
Development

No branches or pull requests

5 participants