```swift
func createTodo() async {
let todo = Todo(name: "my first todo", description: "todo description")
do {
let result = try await Amplify.API.mutate(request: .create(todo))
switch result {
case .success(let todo):
print("Successfully created the todo: \(todo)")
case .failure(let graphQLError):
print("Failed to create graphql \(graphQLError)")
}
} catch let error as APIError {
print("Failed to create a todo: ", error)
} catch {
print("Unexpected error: \(error)")
}
}
```
Make sure you have the additional import at the top of your file
```swift
import Combine
```
```swift
func createTodo() -> AnyCancellable {
let todo = Todo(name: "my first todo", description: "todo description")
let sink = Amplify.Publisher.create {
try await Amplify.API.mutate(request: .create(todo))
}.sink { completion in
if case let .failure(error) = completion {
print("Failed to create graphql \(error)")
}
}
receiveValue: { result in
switch result {
case .success(let todo):
print("Successfully created the todo: \(todo)")
case .failure(let graphQLError):
print("Could not decode result: \(graphQLError)")
}
}
return sink
}
```