Mutation and update cache

Open Todo/TodoVC.swift and add the following function to delete all the completed todos from the cloud.

githubTodo/TodoVC.swift
// Remove all completed Todos from cloud
private func removeAllCompletedTodosCloud(){
apollo.perform(mutation: ClearCompletedMutation()) { (result, error) in
guard let data = result?.data else { return }
if data.deleteTodos?.affectedRows == self.filteredTodos.filter({$0.isCompleted}).count {
self.todos = self.todos.filter({!$0.isCompleted})
self.filteredTodos = self.filteredTodos.filter({!$0.isCompleted})
self.removeTodosMutationLocal(id: -1)
DispatchQueue.main.async {
self.toggleCompleteAction()
}
}
}
}

And finally update the removeAllCompleted function as below

@IBAction func removeAllCompleted(_ sender: Any) {
// Remove all completed todos on click of Remove Completed Button
+ removeAllCompletedTodosCloud()
}

That's a wrap of the todo app.

Close

Get Started with GraphQL Now

Hasura Cloud gives you a fully managed, production ready GraphQL API as a service to help you build modern apps faster.
Ready to get started?
Start for free on Hasura Cloud or you could contact our sales team for a detailed walk-through on how Hasura may benefit your business.
Stay in the know
Sign up for full access to our community highlights, new features, and occasional baby animal gifs! Oh, and we have a strict no-spam rule. ✌️