DEV Community

loading...

Simple Todo - Part 2 of 6

Related Code
Mobile Application Development. Scalable Architecture Design. Custom Backend Development. Application Security. Performance Engineering. Analytics. Maintenance.
・2 min read

In the upcoming versions, we will store the Todo items on a GraphQL server. We can use almost any kind of GraphQL backends (several different variations will be discussed later), but for now, let's start with Amazon AppSync.

On the database layer, we use DynamoDB which will be connected to the AppSync (GraphQL) interface.

Log in to your AWS account and select DynamoDB from the service list. On the left side select Tables and click on the Create table button.

The Table name should be Todo and the Partition key value should be the local database primary key (objectId). All other settings are good as it is, so simply just click the Create table button.

Screenshot

We don't have any other task in DynamoDB other than waiting for the table to be created.

The upcoming steps shall be done on the AppSync console. Please select AWS AppSync from the service list.

Click the Create API button on the top-right corner. Choose the Import DynamoDB Table option and click Start. From the Table name dropdown list pick the recently created Todo table and hit Import.

On the next screen, the GraphQL model should be created according to our local database structure.

Screenshot

When you entered everything as described above, please hit Create. To keep it simple, the API name should also be Todo.

Screenshot

Once AWS is finished creating the API, everything is good to go. The default Schema (created by AWS) covers everything (Queries, Mutations, and Subscriptions), that we need for our iOS implementations.

The API credentials can be found in the AppSync Settings are.

Screenshot

Just to be sure everything is working properly, you can run some tests on the AppSync GraphQL console.

Screenshot

As we are moving forward, we will use the following GraphQL methods.

mutation CreateTodo($object: CreateTodoInput!) {
  createTodo(input: $object) {
    objectId, title, completed, deleted, createdAt, updatedAt
  }
}
Enter fullscreen mode Exit fullscreen mode
mutation UpdateTodo($object: UpdateTodoInput!) {
  updateTodo(input: $object) {
    objectId, title, completed, deleted, createdAt, updatedAt
  }
}
Enter fullscreen mode Exit fullscreen mode
query ListTodos($updatedAt: String) {
  listTodos(filter: {updatedAt: {gt: $updatedAt}}) {
    items {
      objectId, title, completed, deleted, createdAt, updatedAt
    }
  }
}
Enter fullscreen mode Exit fullscreen mode
subscription OnCreateTodo {
  onCreateTodo {
    objectId, title, completed, deleted, createdAt, updatedAt
  }
}
Enter fullscreen mode Exit fullscreen mode
subscription OnUpdateTodo {
  onUpdateTodo {
    objectId, title, completed, deleted, createdAt, updatedAt
  }
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)