Hi, I need to add a JWT header to my GraphQL subsc...
# apollo-kotlin
j
Hi, I need to add a JWT header to my GraphQL subscription - does anyone know how to do this with apollo-android? (and somehow support refreshing jwts as well)
m
You can use
ApolloClient.subscriptionConnectionParams()
to send additional information in the
init
message
Or if you need more control over it, you'll most likely have to implement your own
OperationMessageSerializer
j
Thanks for getting back to me
My subscription fails with
java.io.EOFException
and no other details in
Copy code
@Override
    public void onNetworkError(@NotNull Throwable t) {
      Callback<T> callback = this.originalCallback;
      if (callback != null) {
        callback.onFailure(new ApolloNetworkException("Subscription failed", t));
      }
      terminate();
    }
After a couple of minutes. Any idea what could cause this?
m
Right, I've seen this as well. Not 100% sure what's the root cause. Most probably your backend requires a ping of some sort.
r
The
ApolloRequestInterceptor
does not work with subscriptions @mbonnin?
r
That sounds like a better approach then... use a standard interceptor like the built-in bearer token interceptor or a custom variation, and it should work for both regular calls and subscriptions.
👍 1
j
Yeah the EOF was indeed a backend required ping. I was having issues using the Apollo interceptor for JWT behavior, but will take another look. Thanks both.
👍 1