Skip to content

Instantly share code, notes, and snippets.

View Lavanyagaur22's full-sized avatar
🚩

Lavanya gaur Lavanyagaur22

🚩
View GitHub Profile
package com.lavanya.aerogearlibrary.activities
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import com.apollographql.apollo.ApolloCall
import com.apollographql.apollo.api.Response
import com.apollographql.apollo.exception.ApolloException
import com.lavanya.aerogearlibrary.*
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.apollographql.apollo:gradle-plugin:0.3.2' //Add this
..
}
//In the project build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.apollographql.apollo:gradle-plugin:0.3.2' //Add this
}
//In the app build.gradle
apply plugin: 'com.android.application'
//Add apollographql plugin before the kotlin plugin
apply plugin: 'com.apollographql.android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
...
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.apollographql.apollo:apollo-android-support:0.3.2'
implementation 'com.apollographql.apollo:apollo-runtime:0.3.2'
private fun createtask(title: String, description: String) {
Log.e(TAG, "inside create task")
val client = Utils.getApolloClient(this)?.mutate(
CreateTask.builder().title(title).description(description).build()
)
client?.enqueue(object : ApolloCall.Callback<CreateTask.Data>() {
override fun onFailure(e: ApolloException) {
Log.e("onFailure" + "createTask", e.toString())
fun updateTask(id: String, title: String, version: Int) {
Log.e(TAG, "inside update task")
val client: ApolloMutationCall<UpdateCurrentTask.Data>?
val mutation = UpdateCurrentTask.builder().id(id).title(title).version(version).build()
//I am trying to do something like this but not able to access it as not such method available in apollostore.
// Optimistic Update
// Network.apolloClient
// .apolloStore()
@Override
public <D extends Mutation.Data, T, V extends Mutation.Variables> ApolloMutationCall<T> mutate(
@Nonnull Mutation<D, T, V> mutation) {
return newCall(mutation).cacheControl(CacheControl.NETWORK_ONLY);
}
private fun createtask(title: String, description: String) {
Log.e(TAG, "inside create task")
val client = Utils.getApolloClient(this)?.mutate(
CreateTask.builder().title(title).description(description).build()
)?.refetchQueries(object : OperationName {
override fun name(): String {
return AllTasksQuery.OPERATION_DEFINITION
}
subscription SubscribeData{
subscribeTasks{
id
title
description
version
}
}