aws-amplify / aws-amplify/amplify-android
AppSyncGraphQLRequestFactory.buildQuery build wrong query
- Dominant language
- Java
- Stars
- 287
- Forks
- 132
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 45
Description
### Before opening, please confirm:
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-android/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-android/discussions).
### Language and Async Model
Kotlin
### Amplify Categories
GraphQL API
### Gradle script dependencies
```groovy
// 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
```kotlin
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](https://github.com/aws-amplify/amplify-android/files/9069692/amplifyconfiguration.json.zip)
### GraphQL Schema
```graphql
type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
id: ID!
name: String
description: String
image: String
}
```
### Additional information and screenshots
_No response_
Contributor guide
Research direction
Start at AppSyncGraphQLRequestFactory.buildQuery and trace the operation name produced for ModelQuery.list(NoteData::class.java), using the reported listNoteDatas validation error and NoteData schema as the reproduction. Done means the generated request uses the AppSync field name listNoteData and the list operation succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100