@@ -8,16 +8,75 @@ This project is an example of using Flutter with the AWS AppSync solution. It is
8
8
9
9
[ ![ Demo] ( https://github.com/ineat/flutter-aws-appsync-sample/blob/master/media/demo.gif )] ( https://github.com/ineat/flutter-aws-appsync-sample/blob/master/media/demo.mp4 )
10
10
11
- ### My AppSync Configuration
11
+ AWS AppSync automatically updates web and mobile application data in real time, and offline user data is updated as soon as it is reconnected.
12
+ If you use AppSync as a simple GraphQL API without the subscribe feature then it would be better to use the following plugin: :
13
+ https://pub.dartlang.org/packages/graphql_flutter
14
+
15
+
16
+ The bridge is based on the official documentation of the AppSync SDK.
17
+
18
+ AWS AppSync SDK Android :
19
+ https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-android.html
20
+
21
+ AWS AppSync SDK iOS :
22
+ https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-ios.html
23
+
24
+ If you want more information on the development of a flutter plugin here is an official link: https://flutter.io/developing-packages/
25
+
26
+ To make this example work, AppSync is configured with the following GraphQL schema :
27
+
28
+
29
+ ## GraphQL schema
30
+
31
+ The GraphQL schema:
32
+
33
+ ``` graphql
34
+ type Message {
35
+ id : ID !
36
+ content : String !
37
+ sender : String !
38
+ conversationId : Int !
39
+ }
40
+
41
+ type Mutation {
42
+ newMessage (content : String ! , sender : String ! , conversationId : Int ! ): Message
43
+ }
44
+
45
+ type Query {
46
+ getMessages : [Message ]
47
+ }
48
+
49
+ type Subscription {
50
+ subscribeToNewMessage (conversationId : Int ! ): Message
51
+ @aws_subscribe (mutations : ["newMessage" ])
52
+ }
53
+
54
+ schema {
55
+ query : Query
56
+ mutation : Mutation
57
+ }
58
+ ```
59
+
60
+ Pour créer votre schéma GraphQL pour AppSync, consulter le lien https://docs.aws.amazon.com/appsync/latest/devguide/graphql-overview.html
61
+
62
+ ## Security
63
+
64
+ AppSync will be secured by API Key.
65
+
66
+ https://docs.aws.amazon.com/appsync/latest/devguide/security.html
67
+
68
+ ## Data Source
69
+
70
+ The Data Source used by AppSync is a lambda. Here is this example here is a simplified version :
12
71
13
- ** Lambda called by AppSync :**
14
72
``` javascript
15
73
16
74
var incrementId = 0 ;
17
75
var messages = [];
18
76
19
77
exports .handler = async (event , context , callback ) => {
20
78
switch (event .field ) {
79
+ // match with Data Template resolver
21
80
case ' getMessages' :
22
81
getMessages (event , context, callback);
23
82
break ;
@@ -46,40 +105,12 @@ async function newMessage(event, context, callback) {
46
105
}
47
106
```
48
107
49
- ** Schema GraphQL in App Sync :**
50
-
51
- ``` graphql
52
- type Message {
53
- id : ID !
54
- content : String !
55
- sender : String !
56
- conversationId : Int !
57
- }
58
-
59
- type Mutation {
60
- newMessage (content : String ! , sender : String ! , conversationId : Int ! ): Message
61
- }
108
+ To link the GraphQL schema methods to the lambda refer to the following link : https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html
62
109
63
- type Query {
64
- getMessages : [Message ]
65
- }
66
-
67
- type Subscription {
68
- subscribeToNewMessage (conversationId : Int ! ): Message
69
- @aws_subscribe (mutations : ["newMessage" ])
70
- }
71
-
72
- schema {
73
- query : Query
74
- mutation : Mutation
75
- }
76
- ```
77
-
78
- Settings Authorization type is : ** API key**
79
-
80
- Add ** resolver** into query, mutation. The data source name is linked with the previously lambda.
110
+ ## Resolvers
81
111
82
112
Request template resolver for NewMessage Mutation :
113
+
83
114
``` javascript
84
115
{
85
116
" version" : " 2017-02-28" ,
@@ -92,6 +123,7 @@ Request template resolver for NewMessage Mutation :
92
123
```
93
124
94
125
Request template resolver for GetMessages Query :
126
+
95
127
``` javascript
96
128
{
97
129
" version" : " 2017-02-28" ,
@@ -103,13 +135,20 @@ Request template resolver for GetMessages Query :
103
135
}
104
136
```
105
137
106
- Add AppSync API URL, and API Key in the file /lib/constants.dart
138
+ ## Configuration sample
139
+
140
+ To configure AppSync in the project, modify the constants of the file /lib/constants.dart
141
+
142
+ ``` dart
143
+ const AWS_APP_SYNC_ENDPOINT = "YOUR ENDPOINT"; // like https://xxx.appsync-api.eu-central-1.amazonaws.com/graphql
144
+ const AWS_APP_SYNC_KEY = "YOUR API KEY";
145
+ ```
107
146
108
147
# Custom Configuration in your project
109
148
110
149
## 1. Android
111
150
112
- Step 1: add aws android SDK classpath
151
+ ** _ Step 1:_ ** add aws android SDK classpath
113
152
114
153
115
154
``` groovy
@@ -124,7 +163,7 @@ buildscript {
124
163
125
164
```
126
165
127
- Step 2: Plugin plugin and SDK
166
+ _ ** Step 2:** _ Plugin plugin and SDK
128
167
129
168
``` groovy
130
169
// android/app/build.gradle
@@ -139,15 +178,16 @@ dependencies {
139
178
}
140
179
```
141
180
142
- Step 3: add schema and request GraphQL
181
+ _ ** Step 3:** _ add schema and request GraphQL
143
182
144
183
Copy your files in :
145
184
146
185
/android/app/src/main/graphql/your.package.name/* .graphql
147
186
/android/app/src/main/graphql/your.package.name/* .json
148
187
149
188
150
- Step 4: Configure Android Manifest
189
+ _ ** Step 4:** _ Configure Android Manifest
190
+
151
191
``` xml
152
192
153
193
<manifest xmlns : android =" http://schemas.android.com/apk/res/android"
@@ -166,7 +206,8 @@ Step 4: Configure Android Manifest
166
206
167
207
</manifest >
168
208
```
169
- Step 5: Generation GraphQL models
209
+
210
+ _ ** Step 5:** _ Generation GraphQL models
170
211
171
212
Launch gradle command :
172
213
@@ -177,7 +218,7 @@ Launch gradle command :
177
218
178
219
## 2. iOS
179
220
180
- Step 1: add AWS SDK in your Podfile
221
+ _ ** Step 1:** _ add AWS SDK in your Podfile
181
222
182
223
``` ruby
183
224
target ' Runner' do
@@ -186,14 +227,15 @@ target 'Runner' do
186
227
end
187
228
```
188
229
189
- Step 2: Retrieve all dependencies
230
+ _ ** Step 2:** _ Retrieve all dependencies
231
+
190
232
``` ruby
191
233
pod install
192
234
```
193
235
194
- Caution: Configure your deployment target at 9.0 (Runner.xcworkspace)
236
+ _ Caution: _ Configure your deployment target at 9.0 (Runner.xcworkspace)
195
237
196
- Step 3: add schema and request GraphQL
238
+ _ ** Step 3:** _ add schema and request GraphQL
197
239
198
240
Copy your files in :
199
241
0 commit comments