Skip to content

Commit

Permalink
Merge pull request #3 from salihgueler/add-headless-Amplify-CLI-support
Browse files Browse the repository at this point in the history
Add headless Amplify cli support
  • Loading branch information
salihgueler committed Aug 4, 2022
2 parents f127bd2 + 11d3dba commit 0022319
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 145 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
.idea/
.idea/
.DS_Store
14 changes: 8 additions & 6 deletions README.md
Expand Up @@ -9,6 +9,14 @@ The project uses:
- [Amplify Datastore](https://pub.dev/packages/amplify_datastore) for saving data and real time updates
- [bloc](https://pub.dev/packages/bloc) for state management.

## Requirements 🚀

Before you move forward, be sure to have
- your AWS Account created
- Amplify CLI is installed.

If you do not know how to do it, you can check the [official documentation](https://docs.amplify.aws/start/getting-started/installation/q/integration/flutter/) or this [blog post](https://medium.com/p/ef748798fdbf) for detailed guide.

## How to use 🚀

You can either fill in the variables on your CLI:
Expand All @@ -25,12 +33,6 @@ let CLI guide you through the process
mason make amplify_starter
```

-----

> This project creates the base project for you. You are still expected to configure AWS Amplify afterwards.
>
> Once the project is created go to the [README.md](https://github.com/salihgueler/amplify_starter/blob/main/__brick__/%7B%7Bproject_name%7D%7D/README.md) file of the generated project and follow the steps described there.
## Variables ✨

| Variable | Description | Default | Type |
Expand Down
133 changes: 2 additions & 131 deletions __brick__/{{project_name}}/README.md
Expand Up @@ -11,141 +11,12 @@ The project uses:
-
## Getting Started

> Before you move forward, be sure to have your AWS Account created and Amplify CLI is installed.
>
> If you do not know how to do it, you can check the [official documentation](https://docs.amplify.aws/start/getting-started/installation/q/integration/flutter/) or this [blog post](https://medium.com/p/ef748798fdbf) for detailed guide.
Once the project is created, open your terminal on the generated project path. Afterwards write the following command:
```shell
amplify init
```

This will initialize AWS Amplify for your application.

```shell
msalihg@ AWS TODO % amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project AWSTODO
The following configuration will be applied:

Project information
| Name: AWSTODO
| Environment: dev
| Default editor: Visual Studio Code
| App type: flutter
| Configuration file location: ./lib/

? Initialize the project with the above configuration? Yes
Using default provider awscloudformation
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use default
Adding backend environment dev to AWS Amplify app:
⠼ Initializing project in the cloud...
...
✅ Initialized your environment successfully
```

At above, you have chosen the default configuration for your project, it is more than enough to start with. But, you can always have your own version of the settings as well.

Once you see the success message, you are ready to add libraries. First, add Amplify Authentication library:

```shell
amplify add auth
```

This will take you to select couple of options:
```
msalihg@ AWS TODO % amplify add auth
Using service: Cognito, provided by: awscloudformation
The current configured provider is Amazon Cognito.
Do you want to use the default authentication and security configuration? Default configuration
Warning: you will not be able to edit these selections.
How do you want users to be able to sign in? Username
Do you want to configure advanced settings? No, I am done.
✅ Successfully added auth resource locally
```

Just select the default ones and username as a sign in method. That is enough for Authentication.

Next step is adding the Amplify DataStore.

```shell
amplify add api
```

This is a tricky one. You need to select GraphQL if you would like to work with real time updates.

```shell
msalihg@ AWS TODO % amplify add api
? 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
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Configure additional auth types? No
? 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)
```

You can pick any option from above **but for the sake of the starter project, do the selections as seen like above.**

Now open the `schema.graphql` file from `amplify/backend/api/<{{project_name}}>/schema.graphql` path. Remove everything and paste the following there:

```graphql
type Todo @model @auth(rules: [{ allow: owner }]) {
id: ID!
name: String!
description: String
isComplete: Boolean!
}
```

This will create a Todo object that will be available only for the owner to read/create/update.

Amplify has a tool to help you generate models out of the GraphQL reference.

```shell
amplify codegen models
```

Once you create the models, now you are set to push your changes to cloud. But before write `amplify status` command. It should show you the state of your application and your setup for AWS Amplify.

```shell
msalihg@ {{project_name}} % amplify status

Current Environment: dev

┌──────────┬────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name │ Operation │ Provider plugin │
├──────────┼────────────────────────┼───────────┼───────────────────┤
│ Auth │ {{project_name}} │ Create │ awscloudformation │
├──────────┼────────────────────────┼───────────┼───────────────────┤
│ Api │ {{project_name}} │ Create │ awscloudformation │
└──────────┴────────────────────────┴───────────┴───────────────────┘

GraphQL transformer version: 2
```

You can see that, two categories have been created for your project and now ready to be pushed.
The project is structured and configured for your usage. Only thing you have to do is to change your changes to the cloud __IF__ you have not done it yet.

```shell
amplify push
```

With this command, you are pushing your changes to the cloud. These changes will take a couple of minutes so in the meantime enjoy your coffee.

Once it is done, get the Flutter packages as follows:

```shell
flutter pub get
```

and run your application!
Once it is done, go ahead and run your application!
1 change: 1 addition & 0 deletions __brick__/{{project_name}}/add_api_request.json
@@ -0,0 +1 @@
{"version":1,"serviceConfiguration":{"serviceName":"AppSync","apiName":"apiGraphQl{{project_name.pascalCase()}}","transformSchema":"type Todo @model @auth(rules: [{ allow: owner }]) {\n id: ID!\n name: String!\n description: String\n isComplete: Boolean!\n}","defaultAuthType":{"mode":"AMAZON_COGNITO_USER_POOLS"},"conflictResolution":{"defaultResolutionStrategy":{"type":"AUTOMERGE"}}}}
1 change: 1 addition & 0 deletions __brick__/{{project_name}}/add_auth_request.json
@@ -0,0 +1 @@
{"version": 1,"resourceName": "{{project_name.pascalCase()}}","serviceConfiguration": {"serviceName": "Cognito","userPoolConfiguration": {"signinMethod": "USERNAME","requiredSignupAttributes": ["EMAIL"], "autoVerifiedAttributes": [{"type": "EMAIL"}]},"includeIdentityPool": true}}
4 changes: 2 additions & 2 deletions __brick__/{{project_name}}/lib/main.dart
Expand Up @@ -4,13 +4,13 @@ import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:{{project_name.snakeCase()}}/models/ModelProvider.dart';
import 'package:{{project_name.snakeCase()}}/todos/todos_list/ui/todos_page.dart';
import 'package:{{project_name.snakeCase()}}/profile/domain/remote_user_repository.dart';
import 'package:{{project_name.snakeCase()}}/profile/domain/user_repository.dart';
import 'package:{{project_name.snakeCase()}}/todos/domain/remote_todos_repository.dart';
import 'package:{{project_name.snakeCase()}}/todos/domain/todos_repository.dart';
import 'package:{{project_name.snakeCase()}}/todos/todos_list/ui/todos_page.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'amplifyconfiguration.dart';

Expand Down
10 changes: 5 additions & 5 deletions __brick__/{{project_name}}/pubspec.yaml
Expand Up @@ -31,11 +31,11 @@ dependencies:
sdk: flutter

# Amplify Libraries
amplify_flutter: ^0.6.1
amplify_datastore: ^0.6.1
amplify_authenticator: ^0.2.1
amplify_auth_cognito: ^0.6.1
amplify_api: ^0.6.1
amplify_flutter: ^0.6.5
amplify_datastore: ^0.6.5
amplify_authenticator: ^0.2.2
amplify_auth_cognito: ^0.6.5
amplify_api: ^0.6.5

# Bloc libraries
equatable: ^2.0.3
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
@@ -0,0 +1,3 @@
analyzer:
exclude:
- __brick__/**
4 changes: 4 additions & 0 deletions hooks/.gitignore
@@ -0,0 +1,4 @@
.dart_tool
.packages
pubspec.lock
coverage

0 comments on commit 0022319

Please sign in to comment.