This course is no longer maintained and may be out-of-date. While it remains available for reference, its content may not reflect the latest updates, best practices, or supported features.
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 QueryclearCompletedMutation = ClearCompletedMutation.builder().build()// Apollo runs query on background threadNetwork.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 listval todos = listItems?.filter { task -> task.is_completed }Network.apolloClient.apolloStore().write(GetMyTodosQuery(), GetMyTodosQuery.Data(todos!!)).execute()getMyTodosQueryLocal()}})}
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.
Did you find this page helpful?
Start with GraphQL on Hasura for Free
Build apps and APIs 10x faster
Built-in authorization and caching
8x more performant than hand-rolled APIs

