Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created December 23, 2019 12:55
Show Gist options
  • Save Lavanyagaur22/b918417032c1a8820920fbe198661460 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/b918417032c1a8820920fbe198661460 to your computer and use it in GitHub Desktop.
//Create a mutation object
val input = TaskInput.builder().title(title).version(version).description(description).status("test").build()
val mutation = UpdateTaskMutation.builder().id(id).input(input).build()
//Create an object of apolloCall
val mutationCall = apolloClient.mutate(mutation)?.refetchQueries(apolloQueryWatcher?.operation()?.name())
//Create a callback object of type ApolloCall.Callback
val callback = object : ApolloCall.Callback<UpdateTaskMutation.Data>() {
override fun onResponse(response: Response<UpdateTaskMutation.Data>) {
val result = response.data()?.updateTask()
//In case of conflicts data returned from the server is null.
result?.let {
//Perform UI Bindings.
}
}
/* Called when the request could not be executed due to cancellation, a connectivity problem or timeout.
*/
override fun onFailure(e: ApolloException) {
e.printStackTrace()
}
}
/*Call the enqueue function on ApolloClient on the apollo mutation call and pass callback to it.
*/
mutationCall?.enqueue(callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment