Mutation and update cache

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

// 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 {

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.


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.