Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

Generate model files

For new Amplify apps, we recommend using Amplify Gen 2. You can learn more in our Gen 2 Docs.

With the basic setup complete, next you will model the data that your application will store. Amplify DataStore will use this model to persist data to your local device that will be synchronized to a backend API without writing any additional code.

These models are specified as GraphQL schemas. If you'd like, first learn more about GraphQL schemas and data modeling.

  1. To begin, run the command:
amplify add api

Enter the following when prompted:

? Select from one of the below mentioned services:
`GraphQL`
? Here is the GraphQL API that we will create. Select a setting to edit or continue
`Conflict detection (required for DataStore): Disabled`
? Enable conflict detection?
`Yes`
? Select the default resolution strategy
`Auto Merge`
? Here is the GraphQL API that we will create. Select a setting to edit or continue
`Continue`
? Choose a schema template:
`Single object with fields (e.g., “Todo” with ID, name, description)`
? Do you want to edit the schema now?
`Yes`

This will open a new window. Replace its contents with the following schema:

enum Priority {
LOW
NORMAL
HIGH
}
type Todo @model @auth(rules: [{ allow: public }]) {
id: ID!
name: String!
priority: Priority!
completedAt: AWSDateTime
}

This schema creates a model called Todo with four properties:

  • id: an auto-generated identifier field for a Todo item
  • name: a non-optional string field that is the title of the Todo item
  • priority: a non-optional enumeration type field that indicates the importance of a Todo item; its only available values being LOW, NORMAL, or HIGH
  • completedAt: an optional AWSDateTime field that holds the time of completion of a Todo item
  1. Next, you need to generate the Java objects for these models by running this command in the terminal:
amplify codegen models

The generated models will be added to your project at app/src/main/java/com/amplifyframework/datastore/generated/model