Created
August 1, 2019 19:00
-
-
Save Lavanyagaur22/f029cfe947ccec8cc1147f80a3a79887 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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