-
Notifications
You must be signed in to change notification settings - Fork 79
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
Mock GraphQL API using DataStore doesn't work #322
Comments
Further investigation revealed that adding
My updated model declaration:
It seems like the version resolver is not working in a mock environment, and therefore breaking the synchronization flow? |
@blydewright Amplify Mock does not have support for sync resolvers. To test DataStore syncing, the API will have to be deployed to AppSync. Is there any specific reason why you would like to run the DataStore using mock? DataStore should work locally without any servers when sync is not enabled. |
For me, it is a much better development experience to use Amplify mock. It enables quicker iteration during development. Especially, if you are making many changes to the schema. Amplify push takes long enough that it can be slightly annoying when making many changes or trying out new things. Another thing I noticed was that Amplify mock forces you to supply all the values in a model. Otherwise it will throw an error like the following:
With an AppSync deployment it do not get this error when not providing optional fields in a model. |
@yuth as @arnm pointed out above, the development experience and speed in using Mock is the primary advantage. I myself wanted to test flows of using sync locally before pushing to cloud, as I needed to update my schema many many times, and manually deleting the mock sqlite database when I wanted to re-initialise locally, was far easier then destroying an entire environment and re-deploying it again from scratch as I had to do multiple times whilst learning about limitations in modifying keys/relationships between models during deploys. As AppSync doesn't support mock environment right now, perhaps it can be discussed as a potential improvement? Is the lack of AppSync/mock environment support documented anywhere? I found the lack of substantial (up-to-date) documentation to be my biggest hurdle in learning and making progress... otherwise I'm quite excited to be using Amplify :) |
This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems. |
@blydewright @arnm We can make this a feature request for mock, however the key is that the Conflict Resolution will not be locally mockable. For instance Auto Merge logic. Is something very simplistic with mock (accept all writes even on conflict, or alternatively reject on conflict) ok for you? |
@undefobj Yes, that is understandable. If we can define a simple strategy for local mocking, wether it be cached/offline values overwrite any conflicts in mock db or the other way around, works fine with me. Please reference that new issue here for visibility! Thanks! |
@undefobj sounds good :) Thanks for considering this as a feature request 👍 |
I was wondering would if it be possible for local mock env to create a local table and also an additional table that pretended to be the cloudDB (but also running on local machine), as this might let us keep Conflict Resolution. @undefobj would that be better than disabling Conflict Resolution? |
@undefobj Is there any update related to this feature? |
seconded, bump |
I'm having this same error, only with an API error message that's returned from the mock API with a message of "Cannot return null for non-nullable field... _version". It sounds like this may be the same issue as described above. Note that the API is the only thing I'm running in local mock mode. All else (e.g. Auth, Functions, ....) are all running in AWS cloud. Note also that I do NOT get this error if when doing amplify update api or amplify add api I choose No when asked Despite this (sort of) workaround for the
profilePicThumbnail throws "Cannot return null for non-nullable field" errors when no data is provided in the database, even though it's not a required field! This is VERY problematic! Is there a workaround for this? |
I just bumped into this same issue here with |
Thank you for sharing this. It seems that mocking isn't fully supported for DataStore yet. I'll keep my 👀 on this issue. |
Hello guys. I'm stuck with this issue too. |
Sometimes if I don't mock the API, I could connect to the online backend on AWS (even though I was testing locally using However, I could not consistently connect to the online backend while testing locally (sometimes it would just not find the local mock server and return no data). Anyone has advice connecting a local instance to an online backend? |
The problem here is that the mock database does not automatically populate _version and _lastChangedAt. These two fields:
I can confirm this behavior in amplify cli version 10.5.2 |
How is this still broken? The entire "amplify mock" feature is completely useless for any real-world app if it doesn't work with apps that use the conflict detection feature. Note that there seems to be a similar error related to the "owner" field not being filled in when using AMAZON_COGNITO_USER_POOLS with the mock environment. :-( Using version 10.6.1. This might be a showstopper for my long-term adoption of Amplify as serverless development environment. Deployment to the cloud (via "amplify push") is painfully slow if there are any schema changes, so the edit-deploy-test roundtrip really destroys developer productivity waiting on the "deploy" phase. I was hoping that local mocking would reduce the need to use "amplify push" to test every change, but it needs to work for complex real-world apps, including apps that use complex authentication and conflict detection. |
Waiting for a Bug Fix! |
Describe the bug
All operations (saving, syncing etc.) between my client (ReactJS app) and the mock API fail with various reasons. Whereas running the same exact API on cloud stack (after
amplify push
) works 100%.My simple schema
@model
:That generates the following GraphQL schema:
Bootstrap DataStore hack (as first
DataStore.save()
operation was never syncing with cloud - suggested in another thread):An instance is created through a click handler, and a subscription is created at that point too:
The
DataStore.save()
operation correctly creates and saves the Account locally (in IndexedDb), but returns the following error when trying to sync with Mock API:And further to this, it tries to begin syncing with GraphQL requests, which returns:
Amplify CLI Version
4.18.1
To Reproduce
amplify api add
Account
object inamplify/backend/api/app/schema.graphql
amplify codegen models
amplify api update
-- Api key authentication
-- Conflict detection = Optimistic concurrency
-- Enable DataStore for entire API
amplify mock
Expected behavior
The Creating and syncing should produce no errors, as is the case when
amplify push
to cloud and running the app against a "live" API. Mock environment should work in the same way, and is needed to speed up dev!Desktop (please complete the following information):
Windows 10 Pro build 19041 running WSL2 Ubuntu
This stack is setup on Ubuntu - 18.04
NodeJS version: v13.13.0
The text was updated successfully, but these errors were encountered: