Page updated Nov 10, 2023

Generate model files

With the basic setup complete, you can now model the data your application will work with. These models are specified as GraphQL schemas. You can learn more about GraphQL schemas and data modeling. We can start by creating the budget management data model.

Create data model

Make sure you have followed the steps in the Prerequisites section and have the Amplify CLI installed and configured.

  1. In the console, navigate to your project's root.
  2. Run amplify init to initialize your Amplify project.
  3. Enter a name for your project and proceed through the remaining steps. Most of the defaults should be correct for you.
1$ amplify init
2Note: It is recommended to run this command from the root of your app directory
3? Enter a name for the project <project-name>
4The following configuration will be applied:
5
6Project information
7| Name: <project-name>
8| Environment: dev
9| Default editor: Visual Studio Code
10| App type: flutter
11| Configuration file location: ./lib/
12
13? Initialize the project with the above configuration? Yes
14Using default provider awscloudformation
15? Select the authentication method you want to use: AWS profile
16
17For more information on AWS Profiles, see:
18https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
19
20? Please choose the profile you want to use default

After a minute or so, your project will be initialized and you should see the following message printed to the console:

1Deployment state saved successfully.
2✔ Initialized provider successfully.
3✅ Initialized your environment successfully.
4
5Your project has been successfully initialized and connected to the cloud!
6
7Some next steps:
8"amplify status" will show you what you've added already and if it's locally configured or deployed
9"amplify add <category>" will allow you to add features like user login or a backend API
10"amplify push" will build all your local backend resources and provision it in the cloud
11"amplify console" to open the Amplify Console and view your project status
12"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
13
14Pro tip:
15Try "amplify add api" to create a backend API and then "amplify push" to deploy everything
  1. Now, we can run amplify add api to create the data model.

    • For the first prompt, select GraphQL
    • Highlight Authorization modes and press <Enter>. Change it to Amazon Cognito User Pool.
    • Select Default configuration, Username, then No, I am done.
    • Enter N when prompted to Configure additional auth types
    • Select Continue
    • For your schema template, choose Blank Schema
    • When prompted to edit the schema, enter Y

    Your schema.graphql file will open. Replace its contents with the following:

1type BudgetEntry @model @auth(rules: [{ allow: owner }]) {
2 id: ID!
3 title: String!
4 description: String
5 amount: Float!
6}
  1. Save the file.

  2. Back in the console, run amplify push -y.

    Your project will start deploying to AWS. This is a good time to relax and grab a cup of coffee. After a few minutes, you should see the following:

1Deployment state saved successfully.
2
3GraphQL endpoint: <GRAPHQL-ENDPOINT>
4
5GraphQL transformer version: 2
  1. Finally, run amplify codegen models to generate Dart files which enable interacting with the GraphQL schema in a type-safe manner.

Congratulations! You have deployed your first Amplify backend 🎉 You're ready to integrate with the app!