The purpose of this application is to test the Amplify DataStore.
To use, install, and evaluate this application, please do the following:
- Checkout and build Amplify Android @
main
. Publish to your local repository:
./gradlew build publishToMavenLocal
Detailed instructions are in the Contributing Guide.
-
Import this current project into Android studio. Try to build it.
-
Using the
schema.graphql
as below, generate models and deploy an AppSync backend. Make sure that this step updates your local configuration.
enum PostStatus {
ACTIVE
INACTIVE
}
type Post @model {
id: ID!
title: String!
rating: Int!
status: PostStatus!
}
Use amplify init
, amplify add api
. Follow the guide to add a DataStore endpoint --
except choose "Cognito User Pools" as the auth type, instead of API key. Run amplify push
when done, and wait.
- Create a valid Cognito user, in your the user pool you just created.
aws cognito-idp admin-create-user \
--user-pool-id <pool_id_that_amplify_created> \
--username <some_username>
aws cognito-idp admin-set-user-password \
--user-pool-id <pool_id_that_amplify_created> \
--username <some_username> \
--password <some_password> \
--permanent
Add the <some_username>
and <some_password>
values into
app/src/main/res/values/sign_in.xml
. For example, your sign_in.xml
might look as below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="username" type="id">koolusr44</string>
<string name="password" type="id">koolpass99</string>
</resources>
- Re-build this current app and install it on an Android device.
For repeatable results, you should always swipe-kill the app, before running a manual test case:
adb shell am force-stop com.amplifyframework.datastore.sample
adb uninstall com.amplifyframework.datastore.sample
You may also manually update/clear your AppSync backend, while using
this app. It can be useful to do this before opening this app, so that
the app won't sync a bunch of old data. The script in clear-db.sh
is
useful for this.
The best way to understand the behavior of the different buttons is to
read the
MainActivity.java
.
These are the behaviors of the buttons in the portrait mode of the UI:
- CREATE A POST: Create a single post, with some random data. Display this post on the screen.
- UPDATE ALL: Query all posts, and update them all. Display each update on the screen.
- LIST ALL POSTS: List all current posts, onto the screen.
- DELETE ALL POSTS: Query all posts, and delete each one. Display each deletion to the screen.
- SUBSCRIBE...: Start a new subscription. The subscription will emit information about its lifecycle onto the screen.
- STOP EVERYTHING: Stop/cancel any ongoing operation(s). This will cancel mutation, and it would also tear down a subscription.
- CLEAR LOG: This doesn't do anything to the DataStore. This just clears the log in the app window.
- SIGN IN: Sign in to Cognito using the username and password provided
in your
app/src/main/res/values/sign_in.xml
The left side shows client-side state, the right side shows AppSync side state. As of this time, the right side doesn't include _delete, _lastChangedAt, _version, so it is of limited utility.