Apollo-android: Allow queries and mutations over websocket

Created on 29 Jan 2019  路  12Comments  路  Source: apollographql/apollo-android

Right now, queries and mutations must be made using a normal HTTP request. However, it seems that other Apollo clients have the functionality to perform queries and mutations over a websocket. For example:

iOS: https://github.com/apollographql/apollo-ios/pull/220
Browser: https://github.com/apollographql/subscriptions-transport-ws#full-websocket-transport

The reasoning behind why this would be valuable is that in scenarios where there is already an open websocket (an active subscription, for example), we can just reuse the open websocket instead of opening a new connection to the server.

Runtime Feature

Most helpful comment

Is the concern more having a single interface that can be used for both subscriptions and queries/mutations, or is it specifically sending the mutations and queries over the web socket?

At least in our case, it is specifically required for everything to be sent over the web socket. This is because the connection has state associated based on the connection parameters that were specified when the connection was set up. The API is designed to take advantage of this, and queries/mutations that get sent outside of the connection wouldn't work because of this.

All 12 comments

Are you referring to Subscriptions feature? Apollo Android has subscriptions support

I'm aware Apollo has subscription support, but this would be to also allow queries and mutations over the same websocket as subscriptions. As far as I'm aware, queries and mutations are only supported using HTTP right now.

The lack of this feature is a deal-breaker for us too, as WebSocket connections have implicit state provided by the connection params, without which our queries and mutations simply don't work.

that's a very important feature! is anyone looking to implement this?

Just to give the update on this feature request. This is definitely is non trivial as it requires to refactor the our network layer to make it working with HTTP and WebSocket transport layer.

I can start working on it, but again it's a big feature request.

馃憢 iOS maintainer here - One thing to keep in mind is that on the iOS side, SplitNetworkTransport still sends all queries and mutations via HTTP, not the web Socket. It basically looks at the type and then decides whether to use the WebSocket or not. Having everything send directly through the WebSocket is indeed somewhat more difficult.

Is the concern more having a single interface that can be used for both subscriptions and queries/mutations, or is it specifically sending the mutations and queries over the web socket?

Is the concern more having a single interface that can be used for both subscriptions and queries/mutations, or is it specifically sending the mutations and queries over the web socket?

At least in our case, it is specifically required for everything to be sent over the web socket. This is because the connection has state associated based on the connection parameters that were specified when the connection was set up. The API is designed to take advantage of this, and queries/mutations that get sent outside of the connection wouldn't work because of this.

Hi, I really need this feature too. This, unfortunately, prevents us from using this excellent library.

@sav007 Hi, is there any hope that this feature will be available soon?

Not really sure it will be available soon, as it requires quite a lot of changes to the runtime, there are so many parts that very closely coupled to plain OkHttp request / response.

cc @martinbonnin @tasomaniac

@sav007 are there any plans to address this in the near future?
We're still interested in using Apollo, but this issue severely limits what we can do with it.
Cheers!

Hey, it's not officially released or promoted yet but I guess you can try a new apollo-runtime-kotlin module. Unfortunately new runtime doesn't have any caching yet (neither http nor normalized, work still in progress).

So with new runtime you can set network layer up with ApolloWebSocketNetworkTransport.
See https://github.com/apollographql/apollo-android/blob/master/apollo-runtime-kotlin/src/commonMain/kotlin/com/apollographql/apollo/ApolloClient.kt

and https://github.com/apollographql/apollo-android/blob/master/samples/multiplatform/kmp-lib-sample/src/commonMain/kotlin/com/apollographql/apollo/kmpsample/data/ApolloCoroutinesRepository.kt

for reference.

Was this page helpful?
0 / 5 - 0 ratings