11

I'd like to use AWS AppSync for mobile development (Android/iOS) but I’m not sure about its offline capabilities.

According to the documentation the data will be accessible while being offline and synced automatically if the client gets online again. But I can't find any information about if the app client needs to connect to AWS first, before using AppSync to create and modify offline data.

I'm not familiar with the underlying technologies of AppSync (e.g. GraphQL) and I don't have access to the public preview version to test it myself.

I would like to enable privacy-sensitive users to use an app without connecting to AWS while still being able to use AppSync as an offline database. Only if a user later decides to use backup/sync data across devices he or she can opt-in to connect to AWS.

Will this use case be possible with AWS AppSync?

Without using any other local storage (like SharedPreferences, SQLite, Realm, etc.)

Steffen
  • 2,197
  • 2
  • 24
  • 38
  • Can you share some links which for which you are trying to achieve the same? Are you referring this? https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-offline-data-sync – Sreehari Jan 03 '18 at 10:23
  • Thanks for the link. Yes, I would like to know if I can achieve the same (local store) with AWS AppSync. – Steffen Jan 06 '18 at 09:21
  • Appsync uses SQLite internally and stores all data in single table. for queries you have to use graphQL in client instead of SQL/ SQL based ORMs. – srisaiswaroop Aug 02 '18 at 10:12

3 Answers3

1

It should be possible with Firestore, AWS AppSync or your own Backend solution. Any approach you use, you will control when you want to start saving/syncing things online.

You need to handle all this while designing this app. Suggested approach

Let's take example of simple ToDo app

  • I will let User add & save Todos in app

  • All this data will be persisted on disk(using SQLLITE, Preferences or File etc.)

  • If User does clear data or reinstall app, all this data is lost
  • If User wants to go premium, I will let him sync this data with my Backend solution(any one of above-mentioned solution)

Example implementation using Android Shared preference as local storage

public void saveLocalTodo(String title, String details) {
    ArrayList<Todo> todos;
    Todo todo = new Todo(title, details);
    String listOfTodo = sharedPreference.getString(TODOS_LIST, null);
    if (listOfTodo == null)
        todos = new ArrayList<Todo>();
    else
        todos = gson.fromJson(listOfTodo, new TypeToken<ArrayList<Todo>>() {
        }.getType());

    //save at 0th position, recent should always come first
    todos.add(0, todo);
    sharedPreference.edit().putString(TODOS_LIST, gson.toJson(todos)).apply();
}

public ArrayList<Todo> getLocalTodos() {
    ArrayList<Todo> todos;
    String listOfTodos = sharedPreference.getString(TODOS_LIST, null);
    if (listOfTodos == null)
        todos = new ArrayList<Todo>();
    else
        todos = gson.fromJson(listOfTodos, new TypeToken<ArrayList<Todo>>() {
        }.getType());
    return todos;
}

public void saveOnBackend() {
    // Connect to Backend solution

    // Get all local todos from preference
    // Save all at once in batches

    //OR

    // Get all local todos from preference
    // Save one by one
}
Akhil
  • 6,667
  • 4
  • 31
  • 61
  • 2
    Thanks for your reply. But I was wondering if the local cache of AWS AppSync will work without the need for any other local storage (even if the user is not signed in yet). – Steffen Jan 07 '18 at 11:00
  • Sample AWS Appsync App works without any login and stores data in local sqlite in a normalized form. Please read the AWS forum post here https://forums.aws.amazon.com/thread.jspa?threadID=286304&tstart=0 – srisaiswaroop Aug 02 '18 at 10:14
0

Use Realm Database to manage all offline and online data and save if the application uninstall

Mirza Adil
  • 352
  • 5
  • 9
0

you can read https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-reactnative.html

AWS AppSync support offline mode and you can use data base for your app