Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created August 1, 2019 19:00
Show Gist options
  • Save Lavanyagaur22/f029cfe947ccec8cc1147f80a3a79887 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/f029cfe947ccec8cc1147f80a3a79887 to your computer and use it in GitHub Desktop.
class SampleWorker(context: Context, workParameters: WorkerParameters) : OffixWorker(context, workParameters) {
override fun doWork(): Result {
/*
getListOfMutations() returns the list of mutations stored in database in the library.
It's present in the parent class, i.e OffixWorker.
*/
val listOfMutations = getListOfMutations()
//get the mutation one by one from list
listOfMutations.forEach { storedmutation ->
/*
Create an object of Mutation<D,T,V> from the stored mutation in the database.
*/
val obj = getMutation(storedmutation)
/* Make an apollo client which takes in mutation object and makes a call to server.
*/
val customClient = apolloClient.mutate(obj)
customClient?.enqueue(object : ApolloCall.Callback<Operation.Data>() {
override fun onFailure(e: ApolloException) {
e.printStackTrace()
}
/*
On getting a successful response back from the server, delete mutation from the database.
*/
override fun onResponse(response: Response<Operation.Data>) {
// Do your work and delete that mutation by calling the deleteMutation() function.
deleteMutation(storedmutation)
}
})
}
return Result.success()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment