Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
546b304
add StringEnumConverter to JsonSerializerSettings
rose-a Nov 29, 2018
a8cff74
fix dependencies
rose-a Nov 29, 2018
3b51211
Merge branch 'serialize-enums-to-string-by-default' into subscription…
rose-a Nov 29, 2018
e3a2154
change version
rose-a Nov 29, 2018
eca5d24
fix version
rose-a Nov 29, 2018
2911345
fix CloseAsync
rose-a Dec 3, 2018
af78196
lock dispose
rose-a Dec 3, 2018
43cb3dd
implement external exception handling for subscription streams
rose-a Dec 4, 2018
f1deb7f
fix doc comment
rose-a Dec 4, 2018
1a28d69
add back-off delay for automatic reconnects
rose-a Dec 4, 2018
7b19ab5
create GraphQLHttpWebSocket class
rose-a Dec 4, 2018
ad2c31f
get single socket working
rose-a Dec 4, 2018
ae491f2
fix subscription test, cleanup code
rose-a Dec 5, 2018
98190e9
more code cleanup
rose-a Dec 5, 2018
9aec685
add test CanConnectMultipleSubscriptionsSimultaneously
rose-a Dec 5, 2018
24be6a5
dynamically find free ports for integration test
rose-a Dec 5, 2018
4189799
add WebSocketExceptionHandler to clientOptions
rose-a Dec 5, 2018
492c440
move reconnect-logic into subscriptions
rose-a Dec 7, 2018
293c351
move external exception handler declaration to CreateSubscriptionStre…
rose-a Dec 7, 2018
e6c469a
fix exception on disposing disconnected subscription
rose-a Dec 7, 2018
7bcf0e4
fix tests, add console app for testing reconnect after server restart
rose-a Dec 10, 2018
b6e84bf
Update GraphQL.Client.Tests.csproj
Dec 11, 2018
cadd54f
Nullable check (#86)
Dec 11, 2018
3b761e2
Update README.md
Dec 11, 2018
a4c7e60
Merge branch 'subscriptions-api' of github.com:graphql-dotnet/graphql…
rose-a Dec 18, 2018
16a9bd8
create "queue" for requests so that only one send operation is perfor…
rose-a Dec 18, 2018
c37fe83
fix websockets on win 7
rose-a Dec 18, 2018
0562eb8
remove websockets4net dependency
rose-a Dec 18, 2018
881f36d
Update root.props
Jan 7, 2019
6da6ea2
Update config.yml
Jan 7, 2019
a555224
IsTestProject
Jan 7, 2019
b6a26c7
Benchmar
Jan 7, 2019
7f8c05c
benchmark
Jan 10, 2019
ea4a0e8
Update GraphQLLocation.cs
Jan 10, 2019
53c9f81
new Spec
Jan 10, 2019
1add607
mrege from upstream/master
rose-a Jan 22, 2019
bd9bf5e
fix suff for dotnet core 3.0
rose-a Jan 22, 2019
72ba90d
check response for 'null' in where clause
rose-a Jan 22, 2019
f8e1865
add obsolete parameterless constructor to GraphQLRequest
rose-a Jan 22, 2019
632a45d
add debug output in websocket receive
rose-a Jan 22, 2019
f8021af
reuse observables for identical requests
rose-a Jan 22, 2019
95d3319
store changes to consoleapp
rose-a Jan 23, 2019
abd9caf
fix StackOverflowException in GraphQLRequest.GetHashCode()
rose-a Jan 23, 2019
6ab3205
mrege fix-gethashcode
rose-a Jan 23, 2019
93fae18
fix receiving long messages via websocket
rose-a Jan 24, 2019
34db7a4
add obsolete constructor
rose-a Jan 24, 2019
ca4216d
make ReceiveResultStream observable Hot
rose-a Jan 25, 2019
acb36a1
fix multiple subscriptions by using subject in GraphQLHttpWebSocket
rose-a Jan 25, 2019
e70f7a4
fix overlapping subscriptions
rose-a Jan 25, 2019
2fbd83d
fix subscription test to work arround https://github.com/graphql-dotn…
rose-a Jan 28, 2019
e1ba20a
add an observable which publishes all websocket exceptions
rose-a Jan 28, 2019
7984248
fix OnNext calls of exceptionSubject
rose-a Jan 28, 2019
ef37543
fix GraphQLHttpClient(Uri endPoint, GraphQLHttpClientOptions options)…
rose-a Jan 28, 2019
309a8e3
test requests via websockets
rose-a Jan 28, 2019
b9c1443
bump pre-release version
rose-a Jan 28, 2019
3408ff6
fix initializing websocket when multiple threads create a subscriptio…
rose-a Feb 1, 2019
535e1e0
Merge branch 'subscriptions-api' of github.com:graphql-dotnet/graphql…
rose-a Feb 1, 2019
fff86df
Merge branch 'subscriptions-api' into fix-concurrent-subscriptions
rose-a Feb 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion root.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/graphql-dotnet/graphql-client.git</RepositoryUrl>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<Version>2.0.0-alpha.4.subscription-api.7</Version>
<Version>2.0.0-alpha.4.subscription-api.8</Version>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

Expand Down
7 changes: 4 additions & 3 deletions src/GraphQL.Client/Http/GraphQLHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -171,7 +172,7 @@ public IObservable<GraphQLResponse> CreateSubscriptionStream(GraphQLRequest requ

var observable = graphQlHttpWebSocket.CreateSubscriptionStream(request, Options, cancellationToken: _cancellationTokenSource.Token);

subscriptionStreams.Add(request, observable);
subscriptionStreams.TryAdd(request, observable);
return observable;
}

Expand Down Expand Up @@ -202,11 +203,11 @@ public IObservable<GraphQLResponse> CreateSubscriptionStream(GraphQLRequest requ
return subscriptionStreams[request];

var observable = graphQlHttpWebSocket.CreateSubscriptionStream(request, Options, exceptionHandler, _cancellationTokenSource.Token);
subscriptionStreams.Add(request, observable);
subscriptionStreams.TryAdd(request, observable);
return observable;
}

private Dictionary<GraphQLRequest, IObservable<GraphQLResponse>> subscriptionStreams = new Dictionary<GraphQLRequest, IObservable<GraphQLResponse>>();
private ConcurrentDictionary<GraphQLRequest, IObservable<GraphQLResponse>> subscriptionStreams = new ConcurrentDictionary<GraphQLRequest, IObservable<GraphQLResponse>>();

/// <summary>
/// Releases unmanaged resources
Expand Down
61 changes: 33 additions & 28 deletions src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ await this.clientWebSocket.SendAsync(

public Task InitializeWebSocketTask { get; private set; } = Task.CompletedTask;

private object _initializeLock = new object();

#region Private Methods

private Task _backOff()
Expand All @@ -100,36 +102,39 @@ public Task InitializeWebSocket()
if(_disposed != null)
throw new OperationCanceledException();

// if an initialization task is already running, return that
if(InitializeWebSocketTask != null &&
!InitializeWebSocketTask.IsFaulted &&
!InitializeWebSocketTask.IsCompleted)
return InitializeWebSocketTask;

// if the websocket is open, return a completed task
if (clientWebSocket != null && clientWebSocket.State == WebSocketState.Open)
return Task.CompletedTask;

// else (re-)create websocket and connect
//_responseStreamConnection?.Dispose();
clientWebSocket?.Dispose();

// fix websocket not supported on win 7 using
// https://github.com/PingmanTools/System.Net.WebSockets.Client.Managed
clientWebSocket = SystemClientWebSocket.CreateClientWebSocket();
switch (clientWebSocket)
lock (_initializeLock)
{
case ClientWebSocket nativeWebSocket:
nativeWebSocket.Options.AddSubProtocol("graphql-ws");
break;
case System.Net.WebSockets.Managed.ClientWebSocket managedWebSocket:
managedWebSocket.Options.AddSubProtocol("graphql-ws");
break;
default:
throw new NotSupportedException($"unknown websocket type {clientWebSocket.GetType().Name}");
}
// if an initialization task is already running, return that
if(InitializeWebSocketTask != null &&
!InitializeWebSocketTask.IsFaulted &&
!InitializeWebSocketTask.IsCompleted)
return InitializeWebSocketTask;

// if the websocket is open, return a completed task
if (clientWebSocket != null && clientWebSocket.State == WebSocketState.Open)
return Task.CompletedTask;

// else (re-)create websocket and connect
//_responseStreamConnection?.Dispose();
clientWebSocket?.Dispose();

// fix websocket not supported on win 7 using
// https://github.com/PingmanTools/System.Net.WebSockets.Client.Managed
clientWebSocket = SystemClientWebSocket.CreateClientWebSocket();
switch (clientWebSocket)
{
case ClientWebSocket nativeWebSocket:
nativeWebSocket.Options.AddSubProtocol("graphql-ws");
break;
case System.Net.WebSockets.Managed.ClientWebSocket managedWebSocket:
managedWebSocket.Options.AddSubProtocol("graphql-ws");
break;
default:
throw new NotSupportedException($"unknown websocket type {clientWebSocket.GetType().Name}");
}

return InitializeWebSocketTask = _connectAsync(_cancellationTokenSource.Token);
return InitializeWebSocketTask = _connectAsync(_cancellationTokenSource.Token);
}
}

private IObservable<GraphQLWebSocketResponse> _createResponseStream()
Expand Down