-
Notifications
You must be signed in to change notification settings - Fork 247
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 - Sync from DynamoDB to Client - Issue #297
Comments
Not an AWS dev but thought I would comment... DataStore client sync is built on top of AppSync subscription. Writing directly to a DynamoDB table bypasses AppSync. You should be able to make updates using AppSync GraphQL API requests and the clients will sync the new data. https://docs.amplify.aws/guides/functions/graphql-from-lambda/q/platform/js |
Hi @nithin-seenivasan, @kjones is right, DataStore works with graphql and writing directly to the dynamoDB table bypasses it. It's not a recommended flow as well since client side DataStore manages the version numbers for a variety of use cases and writing directly to dynamodb will mess with the versioning and corrupt the data. |
I suspected as much, thank you @kjones and @Amplifiyer for that. So can we conclude that the only way (currently) to trigger a sync on the Client side is by clearing local storage? |
We don't recommend updating DDB directly and using the same tables with DataStore. As you pointed out, calling |
@kjones Thanks for the heads up about GraphQL. I got my app working directly with Appsync, and everything works perfectly. |
@nithin-seenivasan Good to hear. I'm certainly geeking out on this workflow at the moment where the backend can make changes that propagate automatically to the client. I'm using it in a couple of different ways:
|
@kjones My workflow ended up very similar to what you wrote! I'm currently doing - Client -> S3 -> Lambda Trigger -> Lambda -> Appsync -> DDB and Client Datastore In your 2nd scenario, do you send out the data from 3rd party to ALL your clients via Lambda? I had the issue to only send the data that a client uploads to S3 back to the client, so I couldn't have all the users subscribe to the mutation. I ended up using a GraphQL schema with the CognitoUserPool authorized user having exclusive Read, Update and Delete permissions, while public API-key authenticated system (Lambda in this case) can Create. So Lambda, using an API-key writes a mutation to Appsync, mimicking the owner (whose ID i get from my uploaded file's filename in S3 bucket), and the corresponding user, who is subscribed to all mutations bearing their user-ID, receives it down to the client device. It works, but it's a bit roundabout. |
The data coming from 3rd parties is from services the user has authorized via OAuth to send us data on their behalf. So that the data is only visible to a single user I set the models to require owner authorization. For Lambda function access I use IAM. @auth(rules: [{ allow: owner }, { allow: private, provider: iam }]) When saving to AppSync from Lambda, the |
I struggled two days with sync problems and tried all the tricks from these issue threads. Sync was working as expected when using Datastore API with clients, but external mutation using Appsync console didn't trigg the update on client side. Finally I monitored in Chrome developer tools how the Datastore client is making it's mutations and I realized the the client is passing all the fields of the model in mutation. So, after adding all fields into Appsync mutation query it started to work. In documentation it is said that you should include all the required fields, but I don't know how to define if the field is required or not. I didn't have exclamation mark after my fields so I though the fields were optional in mutation query. Apparently they were not. |
This is a bug report I just filed that includes a couple of bugs I found and the workarounds to each |
Describe the bug
DynamoDB to Client sync is not happening unless local storage is cleared first.
Usage scenario:
Amplify.DataStore.save()
(WORKS)The ONLY way I can force these externally written values to DynamoDB to download into Local Storage is if I clear the local storage using
Amplify.DataStore.clear()
and then do a read queryAmplify.DataStore.query(Post.classType);
.To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expected that external changes are made to the DynamoDB table will get synced to the local storage. This could either be -
Platform
Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply):
[X] Android
[] iOS
Smartphone (please complete the following information):
Additonal Data
From Android Studio's Console, showing the sequence from Clearing Local Storage to running the Read Query.
Posted as an issue, discussed with @Amplifiyer on #5
The text was updated successfully, but these errors were encountered: