Closed TheMoums closed 3 years ago
@TheMoums if you inspect the network request for that graphql query in dev tools, do you see a timestamp for lastSync
in the request payload? (Specifically after refreshing the page)
Could you share screenshots or copy-paste the contents of the request payload on initial load (e.g., delete the IDB database and reload) and then after refreshing the page again.
For example, in my sample app, on initial load I see:
(Note lastSync
= 0, which will result in a base sync and return all of the data that matches the predicate as expected)
But then on refresh, I get
Which results in a Delta sync and returns data: []
Hi @iartemiev
My first syncing query looks like
And results with
If I reload the page (same filter i.e. syncExpression), the lastSync variable is correctly set
But everyhing is refetched from the database as shown below
Thanks for sharing that info. The library itself seems to be working as expected then. The issue might be with the AppSync resolver. Are you using a recent version of amplify-cli? If so, are you using custom resolvers (specifically for syncContacts
)?
I'm not using using any custom resolver. However, I'm still using an old amplify-cli version (4.32.1) as I'm waiting for some specific bugs to be fixed to upgrade it.
What's the minimum cli version needed?
@TheMoums selective sync support was added to @aws-amplify/cli in version 4.32.0, however, there may be bugs in the CLI version you're using that have since been fixed that are causing this issue. Could you perhaps try creating a duplicate project with the latest CLI version to see if you're still experiencing the issue there?
I have upgrraded my cli to the latest version (4.41.1) and the problem unfortunately persists
Do you see the same behavior if you do:
In other words, I'm curious if AppSync still performs a base sync for you when there are items in the delta table.
Yes I see the same behaviour.
Below, I have started two pages on localhost:3000 in chrome as well as in edge.
If I perform a mutation, for instance createContact in my chrome browser:
And I reload my edge browser:
I get my new contact, but I'm still syncing all the other ones. (And I'm still re-syncing all the other tables).
@iartemiev Any news on this?
I've attempted multiple different ways but was not able to reproduce this issue.
Let's try this: could you share your Contact
model definition from your schema.graphql and the corresponding sync query resolver (should be amplify/backend/api/<app_name>/build/resolvers/Query.syncContacts.req.vtl
)
Is there a way I can send you this by mail or any other private way?
My contract forbids me to post this code online
Perhaps you could create a private GitHub repo, upload the files containing the requested information, and then add me as a contributor to the repo?
If uploading to a private repo is still considered posting it online per your contract, feel free to reach out to me directly via Discord. My handle is ObjectiveCat#3157
Your teammate SebS reached out to me on Discord and provided the requested files. I was able to reproduce and opened a PR in the CLI repo with a minor bug fix.
It is now working with the latest version of amplify cli.
Thanks a lot!!
Great! Thank you for letting us know
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels or Discussions for those types of questions.
Describe the bug We are trying out the selective sync but the sync operations seem to be called from scratch on every page reload (like if delta sync was not taken into account).
When not using any selective sync and on DataStore.start(), on page refresh, sync operations were returning:
{data: [] }
because nothing had changed.But, with the selective sync, when reloading the page, all sync operations are returning all the data again which is a huge performance drawback.
This issue was supposed to be solved by https://github.com/aws-amplify/amplify-js/pull/7200 But the problem persists anyway. To Reproduce The following configuration
Refetch all data in the sync queries at each refresh, like nothing was synced. (The clientId is the same each time as the user stays logged in and just refreshing the page.) Expected behavior If nothing has changed in the database, the sync operations should be returning
{data: [] }
What is Configured? I'm using the latest version of @aws-amplify/datastore
If applicable, please provide what is configured for Amplify CLI:
Which resources do you have configured?
aws-exports
file:graphql_headers: async () => { const session = await Auth.currentSession(); return { Authorization: session.getIdToken().getJwtToken(), }; }, }, });