-
Notifications
You must be signed in to change notification settings - Fork 249
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
DataStore query from a "public" table returns always an empty list #5649
Comments
Hello @JannicMeetYu I'm sorry you are experiencing this issue. I will attempt to reproduce the issue and get back to you when I have an update. |
Hi @JannicMeetYu, I suspect the issue you're seeing is due the permissions you've set on You can verify this by inspecting the network tab in the web dev tools and observing the GraphQL network event created when attempting to create a model. I suspect that the request is failing because of a permissions error and the UI doesn't show this error leading to the confusion. |
Thanks for your message. We have set these rules manually. So should we update the rights of the Mood Table by "create"? |
Hi @JannicMeetYu, Studio uses private auth rule when making a request. To get your models to sync via the Studio UI add the private rule, then restrict it as necessary (eg. read, create, etc): type Mood @model @auth(rules: [{allow: public, operations: [read]}, { allow: private }]) {
id: ID!
moodName: String!
moodDescription: String
MoodRecordings: [MoodRecording] @hasMany(indexName: "byMood", fields: ["id"])
isPositiveMood: Boolean!
} |
Description
For our project, we are using AWS Amplify DataStore and we created two models which are included below. We added data to the Mood table in Launch Studio and made it public with reading rights for every user. So they query this table and get the data displayed. The user can then select Moods to create MoodRecordings which are getting saved. That's the idea/goal.
The problem is that if I query/fetch the Moods table, I'm always getting an empty list back.
Here is the code example:
Future<List<Mood>> fetchAllMoods() async { try { final moods = await Amplify.DataStore.query(Mood.classType); print('Fetched moods from DataStore: $moods'); return moods; } on DataStoreException catch (e) { throw DataStoreException('Failed to fetch moods: ${e.message}'); } }
The print statement returns: "Fetched moods from DataStore: []"
We have other models in our schema, where all the CRUD operations are working just fine. It's just that case.
In Launch Studio -> Content, I can select the Mood table and I see that the data is there. If I use the "Test GraphQL API" next to it and query the table
query MyQuery { listMoods { items { id moodName moodDescription isPositiveMood } } }
Im getting the expected data from the table, so this works.
I also tried printing out some events to get some insights:
Amplify.Hub.listen(HubChannel.DataStore, (hubEvent) { if (hubEvent.eventName == "modelSynced") { final syncEvent = hubEvent.payload as ModelSyncedEvent; if (syncEvent.modelName == "Mood") { print('Mood model synced. Record count: ${syncEvent.added}'); } } else if (hubEvent.eventName == "syncQueriesFailed") { print('Sync failed: ${hubEvent.payload}'); } else { print('DataStore event: ${hubEvent.eventName}'); } });
Mood model synced. Record count is always 0. Even after DataStore.clear() and .start().
Are there any rights missing? For me, it seems that everything is set up how it needs to be. I just don't get why it is always querying an empty list.
Categories
Steps to Reproduce
Amplify.DataStore.query(...)
Screenshots
No response
Platforms
Flutter Version
3.24.4
Amplify Flutter Version
2.3.0
Deployment Method
Amplify CLI (Gen 1)
Schema
The text was updated successfully, but these errors were encountered: