File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
src/fragments/lib/graphqlapi/flutter Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff 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
3137Future<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 >
Original file line number Diff line number Diff line change 22
33Now 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
610Future<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
2453You can get the list of items in ` Amplify.API.query ` :
You can’t perform that action at this time.
0 commit comments