0

I am using Apollo Normalized SQL Cache for caching the user data such as user id, name and phone number in Android. Is there a way that I could fetch that information whenever I need irrespective of the query being fired or not?

The response of the query stored in cache.

query loginUser($mobile: String!, $password: String!) {
    login(mobile: $mobile, password: $password){
        token
        id
    }
}

ApolloClient.java

public class OtherAplClient {
    public static final String BASE_URL = AplClient.BASE_URL; 

    public static ApolloClient getmApolloClient() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder().build();

        return ApolloClient.builder()
                .serverUrl(BASE_URL)
                .okHttpClient(okHttpClient)
                .build();
    }
}

Here I want to read the cache

ApolloClient apolloClient = OtherAplClient.getmApolloClient();
        // Here I want to read the cache
Ayush Sahu
  • 59
  • 1
  • 7

1 Answers1

-2

What you need is the ApolloStore, see here https://www.apollographql.com/docs/kotlin/caching/store The ApolloStore is the cache and can be read by you.

Example from https://www.apollographql.com/docs/kotlin/caching/troubleshooting

val dump = apolloClient.apolloStore.dump()
NormalizedCache.prettifyDump(dump)
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270