Skip to content

Commit f1191ec

Browse files
Travis SheppardRachel Lee Nabors
authored andcommitted
chore(flutter): GQL model helper changes for CPK in dev preview (#5124)
1 parent c1fb1c5 commit f1191ec

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/fragments/lib/graphqlapi/flutter/mutate-data.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,37 @@ Future<void> deleteTodo(Todo todoToDelete) async {
2626
final response = await Amplify.API.mutate(request: request).response;
2727
print('Response: $response');
2828
}
29+
```
30+
31+
<BlockSwitcher>
2932

33+
<Block name="Stable (Mobile)">
34+
35+
```dart
3036
// or delete by ID, ideal if you do not have the instance in memory, yet
3137
Future<void> deleteTodoById(Todo todoToDelete) async {
3238
final request = ModelMutations.deleteById(Todo.classType, '8e0dd2fc-2f4a-4dc4-b47f-2052eda10775');
3339
final response = await Amplify.API.mutate(request: request).response;
3440
print('Response: $response');
3541
}
3642
```
43+
44+
</Block>
45+
46+
<Block name="Developer Preview (Mobile, Web & Desktop)">
47+
48+
```dart
49+
// or delete by ID, ideal if you do not have the instance in memory, yet
50+
Future<void> deleteTodoById(Todo todoToDelete) async {
51+
final request = ModelMutations.deleteById(
52+
Todo.classType,
53+
TodoModelIdentifier(id: '8e0dd2fc-2f4a-4dc4-b47f-2052eda10775'),
54+
);
55+
final response = await Amplify.API.mutate(request: request).response;
56+
print('Response: $response');
57+
}
58+
```
59+
60+
</Block>
61+
62+
</BlockSwitcher>

src/fragments/lib/graphqlapi/flutter/query-data.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Now that you were able to make a mutation, take the `id` from the created `Todo` instance and use it to retrieve data.
44

5+
<BlockSwitcher>
6+
7+
<Block name="Stable (Mobile)">
8+
59
```dart
610
Future<Todo?> queryItem(Todo queriedTodo) async {
711
try {
@@ -19,6 +23,31 @@ Future<Todo?> queryItem(Todo queriedTodo) async {
1923
}
2024
```
2125

26+
</Block>
27+
28+
<Block name="Developer Preview (Mobile, Web & Desktop)">
29+
30+
```dart
31+
Future<Todo?> queryItem(Todo queriedTodo) async {
32+
try {
33+
final request = ModelQueries.get(Todo.classType, queriedTodo.modelIdentifier);
34+
final response = await Amplify.API.query(request: request).response;
35+
final todo = response.data;
36+
if (todo == null) {
37+
print('errors: ${response.errors}');
38+
}
39+
return todo;
40+
} on ApiException catch (e) {
41+
print('Query failed: $e');
42+
return null;
43+
}
44+
}
45+
```
46+
47+
</Block>
48+
49+
</BlockSwitcher>
50+
2251
## List items
2352

2453
You can get the list of items in `Amplify.API.query`:

0 commit comments

Comments
 (0)