From 59c0cc39dba961bc45052761160143b1eea19a4e Mon Sep 17 00:00:00 2001 From: Colin Helliwell Date: Sun, 9 Jun 2019 13:01:54 +0100 Subject: [PATCH 1/4] Use HTTP TLS credentials on WebSocket connection --- src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs b/src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs index eb2881ba..d83c106d 100644 --- a/src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs +++ b/src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs @@ -12,6 +12,7 @@ using GraphQL.Common.Request; using GraphQL.Common.Response; using Newtonsoft.Json; +using System.Net.Http; namespace GraphQL.Client.Http { @@ -125,9 +126,13 @@ public Task InitializeWebSocket() { case ClientWebSocket nativeWebSocket: nativeWebSocket.Options.AddSubProtocol("graphql-ws"); + nativeWebSocket.Options.ClientCertificates = ((HttpClientHandler)(_options.HttpMessageHandler)).ClientCertificates; + nativeWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)(_options.HttpMessageHandler)).UseDefaultCredentials; break; case System.Net.WebSockets.Managed.ClientWebSocket managedWebSocket: managedWebSocket.Options.AddSubProtocol("graphql-ws"); + managedWebSocket.Options.ClientCertificates = ((HttpClientHandler)(_options.HttpMessageHandler)).ClientCertificates; + managedWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)(_options.HttpMessageHandler)).UseDefaultCredentials; break; default: throw new NotSupportedException($"unknown websocket type {clientWebSocket.GetType().Name}"); From 22cc5a309e2d5c1c4265107ac4e60b3f2d4a770b Mon Sep 17 00:00:00 2001 From: Colin Helliwell Date: Sun, 9 Jun 2019 13:15:39 +0100 Subject: [PATCH 2/4] Send 'connection_init' in CreateSubscriptionStream (https://github.com/graphql-dotnet/graphql-client/issues/116) --- .../Http/GraphQLHttpSubscriptionHelpers.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/GraphQL.Client/Http/GraphQLHttpSubscriptionHelpers.cs b/src/GraphQL.Client/Http/GraphQLHttpSubscriptionHelpers.cs index 4ba91205..5818d2d8 100644 --- a/src/GraphQL.Client/Http/GraphQLHttpSubscriptionHelpers.cs +++ b/src/GraphQL.Client/Http/GraphQLHttpSubscriptionHelpers.cs @@ -94,6 +94,23 @@ internal static IObservable CreateSubscriptionStream( }) ); + var initRequest = new GraphQLWebSocketRequest + { + Id = startRequest.Id, + Type = GQLWebSocketMessageType.GQL_CONNECTION_INIT, + }; + Debug.WriteLine($"sending init on subscription {startRequest.Id}"); + // send subscription request + try + { + await graphQlHttpWebSocket.SendWebSocketRequest(initRequest).ConfigureAwait(false); + //await graphQlHttpWebSocket.SendWebSocketRequest(startRequest); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } Debug.WriteLine($"sending initial message on subscription {startRequest.Id}"); // send subscription request try From 466ab9dad4e6efca6bba2bfc67d46ac6c7d4fe5c Mon Sep 17 00:00:00 2001 From: Colin Helliwell Date: Thu, 20 Jun 2019 14:31:53 +0100 Subject: [PATCH 3/4] Added a delay to the 'CanConnectTwoSubscriptionsSimultaneously' test, to make it more reliable --- tests/GraphQL.Integration.Tests/SubscriptionsTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/GraphQL.Integration.Tests/SubscriptionsTest.cs b/tests/GraphQL.Integration.Tests/SubscriptionsTest.cs index fb704ad4..e4346941 100644 --- a/tests/GraphQL.Integration.Tests/SubscriptionsTest.cs +++ b/tests/GraphQL.Integration.Tests/SubscriptionsTest.cs @@ -220,6 +220,7 @@ public async void CanConnectTwoSubscriptionsSimultaneously() var tester2 = observable2.SubscribeTester(); const string message1 = "Hello World"; + await Task.Delay(200); // seems to be needed for test to be reliable var response = await client.AddMessageAsync(message1).ConfigureAwait(false); Assert.Equal(message1, (string)response.Data.addMessage.content); tester.ShouldHaveReceivedUpdate(gqlResponse => From b3bf32c91fb3a21f1a31b8c3eb64e5f799697189 Mon Sep 17 00:00:00 2001 From: Colin Helliwell Date: Thu, 31 Oct 2019 14:02:57 +0000 Subject: [PATCH 4/4] Changed definition of NuGet icons (NU5048 deprecation). --- src/GraphQL.Client/GraphQL.Client.csproj | 7 ++++++- src/GraphQL.Common/GraphQL.Common.csproj | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/GraphQL.Client/GraphQL.Client.csproj b/src/GraphQL.Client/GraphQL.Client.csproj index 8043bf35..0fa6da96 100644 --- a/src/GraphQL.Client/GraphQL.Client.csproj +++ b/src/GraphQL.Client/GraphQL.Client.csproj @@ -1,4 +1,4 @@ - + @@ -6,12 +6,17 @@ A GraphQL Client netstandard2.0 + + + + + diff --git a/src/GraphQL.Common/GraphQL.Common.csproj b/src/GraphQL.Common/GraphQL.Common.csproj index 116ff1b9..93f0ff4b 100644 --- a/src/GraphQL.Common/GraphQL.Common.csproj +++ b/src/GraphQL.Common/GraphQL.Common.csproj @@ -1,4 +1,4 @@ - + @@ -9,6 +9,7 @@ netstandard2.0 + @@ -16,4 +17,9 @@ + + + + +