Mutation and update cache

Open TaskFragment.kt and add the following function to delete all the completed todos from the cloud.

private fun removeAllCompletedCloud(){
// Init Query
clearCompletedMutation = ClearCompletedMutation.builder().build()
// Apollo runs query on background thread
Network.apolloClient.mutate(clearCompletedMutation)?.enqueue(object : ApolloCall.Callback<ClearCompletedMutation.Data>() {
override fun onFailure(error: ApolloException) {
Log.d("Todo", error.toString() )
override fun onResponse(@NotNull response: Response<ClearCompletedMutation.Data>) {
// get data from local cache and update the list
val todos = listItems?.filter { task -> task.is_completed }
.write(GetMyTodosQuery(), GetMyTodosQuery.Data(todos!!)).execute()

And finally update the removeAllCompleted function as below

private fun removeAllCompleted() {
- // Todo : Method for clearing all completed task at once
+ removeAllCompletedCloud()

That's a wrap of the todo app.