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

Page updated Apr 29, 2024

Set up Amplify GraphQL API

The Amplify API category provides an interface for retrieving and persisting your model data. The API category comes with default built-in support for AWS AppSync. The Amplify CLI allows you to define your API and provision a GraphQL service with CRUD operations and real-time functionality.


To setup and configure your application with Amplify API to save items in the backend.


  • Install and configure Amplify CLI

  • A Flutter application targeting Flutter SDK >= 3.3.0 with Amplify libraries integrated

    The following are also required, depending on which platforms you are targeting:

    • An iOS configuration targeting at least iOS 13.0 and XCode version >=13.2
    • An Android configuration targeting at least Android API level 24 (Android 7.0) or above
    • Any browser supported by Flutter for Web (you can check the list of supported browsers here)
    • Any Windows OS meeting Flutter minimums
    • macOS version 10.15 or higher
    • Any Ubuntu Linux distribution meeting Flutter minimums
    • For a full example please follow the project setup walkthrough

Configure API

To start provisioning API resources in the backend, go to your project directory and execute the command:

amplify add api

Enter the following when prompted:

? Please select from one of the below mentioned services:
# The part below will show you some options you can change, if you wish to change any of them you can navigate with
# your arrow keys and update any field, otherwise you can click on `Continue` to move on
? Here is the GraphQL API that we will create. Select a setting to edit or continue
? Choose a schema template:
`Single object with fields (e.g., “Todo” with ID, name, description)`
? Do you want to edit the schema now?

Troubleshooting: The AWS API plugins do not support conflict detection. If AppSync returns errors about missing _version and _lastChangedAt fields, or unhandled conflicts, disable conflict detection. Run amplify update api, and choose Disable conflict detection. If you started with the Getting Started guide, which introduces DataStore, this step is required.

The guided schema creation will output amplify/backend/api/{api_name}/schema.graphql containing the following:

type Todo @model {
id: ID!
name: String!
description: String

To push your changes to the cloud, execute the command:

amplify push

Upon completion, amplifyconfiguration.dart will be updated to reference provisioned backend resources. Note that this file should already be a part of your project if you followed the Project setup walkthrough.

Generate Todo Model class

To generate the Todo model, change directories to your project folder and execute the command:

amplify codegen models

The generated files will be under the lib/models directory by default. They get re-generated each time codegen is run.

Install Amplify Libraries

Add the following dependencies to your pubspec.yaml file and install dependencies when asked:

sdk: ">=2.18.0 <4.0.0"
sdk: flutter
amplify_flutter: ^1.0.0
amplify_api: ^1.0.0

Initialize Amplify API

To initialize the Amplify API category you call Amplify.addPlugin() method. To complete initialization call Amplify.configure().

Your code should look like this:

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';
import 'amplifyconfiguration.dart';
import 'models/ModelProvider.dart';
class MyApp extends StatefulWidget {
const MyApp({super.key});
State<MyApp> createState() => _MyAppState();
class _MyAppState extends State<MyApp> {
void initState() {
Future<void> _configureAmplify() async {
final api = AmplifyAPI(modelProvider: ModelProvider.instance);
await Amplify.addPlugin(api);
try {
await Amplify.configure(amplifyconfig);
} on Exception catch (e) {
safePrint('An error occurred configuring Amplify: $e');
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Home'),

Create a Todo

Future<void> createTodo() async {
try {
final todo = Todo(name: 'my first todo', description: 'todo description');
final request = ModelMutations.create(todo);
final response = await Amplify.API.mutate(request: request).response;
final createdTodo =;
if (createdTodo == null) {
safePrint('errors: ${response.errors}');
safePrint('Mutation result: ${}');
} on ApiException catch (e) {
safePrint('Mutation failed: $e');

Upon successfully executing this code, you should see an instance of todo persisted in your dynamoDB table.

To navigate to your backend, run amplify console api and choose GraphQL. This will open the AppSync console to your GraphQL service. Select Data Sources and select the Resource link in your TodoTable to bring you to the DynamoDB Console. Select the items tab to see the Todo object that has been persisted in your database.

Next steps

Congratulations! You've created a Todo object in your database. Check out the following links to see other Amplify API use cases: