Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/fragments/lib/graphqlapi/flutter/mutate-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,37 @@ Future<void> deleteTodo(Todo todoToDelete) async {
final response = await Amplify.API.mutate(request: request).response;
print('Response: $response');
}
```

<BlockSwitcher>

<Block name="Stable (Mobile)">

```dart
// or delete by ID, ideal if you do not have the instance in memory, yet
Future<void> deleteTodoById(Todo todoToDelete) async {
final request = ModelMutations.deleteById(Todo.classType, '8e0dd2fc-2f4a-4dc4-b47f-2052eda10775');
final response = await Amplify.API.mutate(request: request).response;
print('Response: $response');
}
```

</Block>

<Block name="Developer Preview (Mobile, Web & Desktop)">

```dart
// or delete by ID, ideal if you do not have the instance in memory, yet
Future<void> deleteTodoById(Todo todoToDelete) async {
final request = ModelMutations.deleteById(
Todo.classType,
TodoModelIdentifier(id: '8e0dd2fc-2f4a-4dc4-b47f-2052eda10775'),
);
final response = await Amplify.API.mutate(request: request).response;
print('Response: $response');
}
```

</Block>

</BlockSwitcher>
29 changes: 29 additions & 0 deletions src/fragments/lib/graphqlapi/flutter/query-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

<BlockSwitcher>

<Block name="Stable (Mobile)">

```dart
Future<Todo?> queryItem(Todo queriedTodo) async {
try {
Expand All @@ -19,6 +23,31 @@ Future<Todo?> queryItem(Todo queriedTodo) async {
}
```

</Block>

<Block name="Developer Preview (Mobile, Web & Desktop)">

```dart
Future<Todo?> queryItem(Todo queriedTodo) async {
try {
final request = ModelQueries.get(Todo.classType, queriedTodo.modelIdentifier);
final response = await Amplify.API.query(request: request).response;
final todo = response.data;
if (todo == null) {
print('errors: ${response.errors}');
}
return todo;
} on ApiException catch (e) {
print('Query failed: $e');
return null;
}
}
```

</Block>

</BlockSwitcher>

## List items

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