amplify-flutter
amplify-flutter copied to clipboard
Datastore Hub Channel failing to emit "ready" event when the type is named ModelXXXConnection
Description
I had an issue where I don't get 'ready' event from hub channel.
StreamSubscription dsHub =
Amplify.Hub.listen([HubChannel.DataStore], (hubEvent) {
});
dsHub.onData((data) async {
if (data.eventName == 'ready') {
getProfile();
await dsHub.cancel();
} else {
print(data.eventName);
}
});
Code above just emit following message indefinitely.
flutter: syncQueriesStarted
flutter: modelSynced
It was happening 100% of the time when I start an app so I decided to revert my code little by little until I narrowed down the issue. And it seems to me that the name of the type in schema.graphql has something to do with this issue.
For example, if I have a model type named SearchableProperties, and add another type ModelSearchablePropertiesConnection, I run into this issue.
type SearchableProperties @model @auth(rules: [{allow: public}]) {
...
}
type Query {
searchNearbyUsers(
filter: searchNearbyUsersInput!,
gps: GpsInput!,
limit: Int,
nextToken: String
): ModelSearchablePropertiesConnection
}
type ModelSearchablePropertiesConnection {
items: [SearchableProperties]
total: Int
nextToken: String
}
I tried few different variations and it's the name Model{model name}Connection that's running into this issue.
I didn't have this issue when tried with names like SearchablePropertiesConnection, ModelSearchableProperties, or ModelSearchable.
Categories
- [ ] Analytics
- [ ] API (REST)
- [X] API (GraphQL)
- [ ] Auth
- [ ] Authenticator
- [X] DataStore
- [ ] Storage
Steps to Reproduce
No response
Screenshots
No response
Platforms
- [X] iOS
- [ ] Android
Android Device/Emulator API Level
No response
Environment
octor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.69.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
Dependencies
Dart SDK 2.17.6
Flutter SDK 3.0.5
cuppacoffee 1.0.0+1
dependencies:
- amplify_api 0.5.1 [amplify_api_plugin_interface amplify_core amplify_api_android amplify_api_ios collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.5.1 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_auth_plugin_interface amplify_core collection flutter plugin_platform_interface]
- amplify_authenticator 0.1.2 [amplify_auth_cognito amplify_auth_plugin_interface amplify_core amplify_flutter collection flutter flutter_localizations intl]
- amplify_datastore 0.5.1 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_datastore_plugin_interface 0.5.1 [flutter meta collection amplify_core]
- amplify_flutter 0.5.1 [amplify_analytics_plugin_interface amplify_api_plugin_interface amplify_auth_plugin_interface amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios amplify_storage_plugin_interface collection flutter json_annotation meta plugin_platform_interface]
- amplify_storage_s3 0.5.1 [flutter amplify_storage_plugin_interface plugin_platform_interface amplify_storage_s3_android amplify_storage_s3_ios amplify_core]
- cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- cupertino_icons 1.0.5
- dropdown_button2 1.6.3 [flutter]
- email_validator 2.0.1
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 8.0.1 [flutter bloc provider]
- flutter_feather_icons 2.0.0+1 [flutter]
- flutter_image_compress 1.1.0 [flutter]
- geocoding 2.0.4 [flutter geocoding_platform_interface]
- geolocator 9.0.1 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- intl 0.17.0 [clock path]
- material_design_icons_flutter 5.0.6595 [flutter]
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- percent_indicator 4.2.2 [flutter]
- permission_handler 10.0.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- provider 6.0.3 [collection flutter nested]
- quiver 3.1.0 [matcher]
transitive dependencies:
- amplify_analytics_plugin_interface 0.5.1 [amplify_core flutter meta]
- amplify_api_android 0.5.1 [flutter]
- amplify_api_ios 0.5.1 [amplify_core flutter]
- amplify_api_plugin_interface 0.5.1 [amplify_core collection flutter json_annotation meta]
- amplify_auth_cognito_android 0.5.1 [flutter]
- amplify_auth_cognito_ios 0.5.1 [amplify_core flutter]
- amplify_auth_plugin_interface 0.5.1 [amplify_core flutter meta]
- amplify_core 0.5.1 [collection date_time_format flutter meta plugin_platform_interface uuid]
- amplify_flutter_android 0.5.1 [flutter]
- amplify_flutter_ios 0.5.1 [amplify_core flutter]
- amplify_storage_plugin_interface 0.5.1 [flutter meta amplify_core]
- amplify_storage_s3_android 0.5.1 [flutter]
- amplify_storage_s3_ios 0.5.1 [flutter]
- async 2.8.2 [collection meta]
- bloc 8.0.3 [meta]
- cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- date_time_format 2.0.1
- ffi 2.0.1
- file 6.1.2 [meta path]
- flutter_blurhash 0.7.0 [flutter]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_plugin_android_lifecycle 2.0.6 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- geocoding_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- geolocator_android 4.0.2 [flutter geolocator_platform_interface]
- geolocator_apple 2.2.1 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.0.6 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.1.6 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.1.1 [flutter geolocator_platform_interface]
- http 0.13.4 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.5+1 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.5+6 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface]
- js 0.6.4
- json_annotation 4.5.0 [meta]
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- nested 1.0.0 [flutter]
- octo_image 1.0.2 [flutter flutter_blurhash]
- path 1.8.1
- path_provider_android 2.0.16 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.10 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.0 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- permission_handler_android 10.0.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.4 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- rxdart 0.27.4
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- sqflite 2.0.3 [flutter sqflite_common path]
- sqflite_common 2.2.1+1 [synchronized path meta]
- stack_trace 1.10.0 [path]
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0+2
- term_glyph 1.2.0
- typed_data 1.3.0 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- win32 2.7.0 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
Device
ios simulator
OS
N/A
CLI Version
9.1.0
Additional Context
No response
Hi @skim037 I think that's the same issue I described here: https://github.com/aws-amplify/amplify-flutter/issues/1921#issuecomment-1197289080
I reviewed amplify-ios logic that the choices of mode names don't have anything to do with the sync process. The known issue in amplify-ios is caused by some race conditions, it may emit ready event occasionally but in the most test cases I don't see ready event gets emitted.
Hi @skim037 with the release of amplify-flutter 0.6.6 the underlying issue in amplify-ios that preventing emitting ready event should've been fixed. Can you give it a try when you get a chance? Thanks! Please feel free to reopen if issue persists or anything else that we can help with.
This is actually happening? I am trying to debug my situation on Javascript and I am not receiving events from the Hub under the datastore scope and I do have models with "Connection" Suffix such as SkillParticipantConnection
My code in summary looks like this:
signIn: async (email: Email, password: string, callback?: () => void) => {
const cognitoUser: CognitoUserExt = await Auth.signIn(email, password)
const profileService = new ProfileService({ userId: cognitoUser.attributes.sub })
let profileExt: ProfileExt
let professions: Profession[] = []
let companies: Company[] = []
console.log('Waiting for profile to be synced') // ---> gets called ✅
// Keep the user in sync with the relevant data from Profile
Hub.listen('datastore', async (hubData) => {
console.log('@authentication loading Datastore', hubData.payload.event) // ---> Never gets called ❌
const { event, data } = hubData.payload
...
if (event === 'syncQueriesPartialSyncError') {
notify.error('Error syncing data, please contact support at [email protected]')
}
// https://docs.amplify.aws/lib/datastore/datastore-events/q/platform/js/#ready
if (event === 'ready') {
console.log('@authentication DataStore is ready')
// profileExt might not have the companies/professions at the moment the `Profile` model is synced
dispatch(syncUser({ ...profileExt, professions, companies }))
callback?.()
}
})
// Allow to activate all subscriptions to sync cloud data
await DataStore.start()
analytics.identify(email)
analytics.trackEvent('LOGIN')
return true
},