I am new to GraphQL so I want to test somethings before starting my own project. As a test database I am using Prisma test database(s) and service(s) and Apollo Android as a library in my application. I am almost done with query
and mutation
. As a next I want to do something with subscription
. So, my graphql subscription looks like:
subscription observer {
post {
mutation
node {
id
title
text
isPublished
}
}
}
As Apollo Android library generates some classes based on my graphql code, I tried to use the observer
subscription like this:
Interceptor interceptor = chain -> chain.proceed(chain.request());
OkHttpClient ohc = new OkHttpClient.Builder().addInterceptor(interceptor).build();
ApolloClient mApolloClient = ApolloClient.builder().serverUrl(ENDPOINT).okHttpClient(ohc).build();
mApolloClient.subscribe(ObserverSubscription.builder().build()).execute(new ApolloSubscriptionCall.Callback<ObserverSubscription.Data>() {
@Override
public void onResponse(@NotNull Response<ObserverSubscription.Data> response) {
// do work here
}
@Override
public void onFailure(@NotNull ApolloException e) {
// catch exception
}
@Override
public void onCompleted() {
// some other stuff goes here
}
});
When executing this codes following exception thrown:
java.lang.IllegalStateException: Subscription manager is not configured
This message comes from here and it is directly related with this.
My question is there any way to use subscriptions using apollo-android in Android app?