Skip to content

Conversation

@rose-a
Copy link
Collaborator

@rose-a rose-a commented Jan 28, 2019

Improvements to the Subscription API (#25)

Single websocket per client

There is only a single websocket connection established per client. This connection is shared across all subscriptions and optionally requests.

Requests via websocket

By setting GraphQLHttpClientOptions.UseWebSocketForQueriesAndMutations = true you can force requests and mutations to use the websocket too, which can reduce the connection overhead on regular requests.

Re-establish subscriptions on connection loss

If the receiving pipeline of the WebSocket encounters a WebSocketException, the client tries to re-establish the connection and on success re-initiates all current subscriptions to the server.

Since this prevents all WebsocketExceptions from reaching the Observer, all exceptions occurring in the receiving pipeline are submitted to the GraphQLHttpClient.WebSocketReceiveErrors observable (i.e. for logging purposes.

This behaviour can be overridden per subscription by using the GraphQLHttpClient.CreateSubscriptionStream(GraphQLRequest request, Action<Exception> exceptionHandler) overload and re-throwing the exception inside the exceptionHandler

Reuse subscriptions for identical requests

The created observables for subscriptions are cached in GraphQLHttpClient. If a second subscription is made with the identical request, the existing observable is returned (instead of creating a second subscription to the server)

Receive long response messages from the WebSocket

The receiving loop now keeps reading into a smaller buffer until WebSocketReceiveResult.EndOfMessage becomes true.

Windows 7 compatibility

The usage of ClientWebSocket throws a PlatformNotSupportedException on Windows 7 (since Microsoft did not implement it there).

This is fixed by using https://github.com/PingmanTools/System.Net.WebSockets.Client.Managed

rose-a and others added 30 commits November 29, 2018 08:42
* nonnullable

* fix some things

* other fix

* netstandard2.0
@deinok deinok merged commit 3ee031a into graphql-dotnet:subscriptions-api Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants