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.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin
graphql-handbook