Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/GraphQL.Client/GraphQL.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../src.props" />

<PropertyGroup>
<Description>A GraphQL Client</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageIconUrl />
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\GraphQL.Common\GraphQL.Common.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="../../assets/logo.64x64.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
<PackageReference Include="System.Net.WebSockets.Client.Managed" Version="1.0.22" />
Expand Down
17 changes: 17 additions & 0 deletions src/GraphQL.Client/Http/GraphQLHttpSubscriptionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ internal static IObservable<GraphQLResponse> 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
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQL.Client/Http/GraphQLHttpWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using GraphQL.Common.Request;
using GraphQL.Common.Response;
using Newtonsoft.Json;
using System.Net.Http;

namespace GraphQL.Client.Http
{
Expand Down Expand Up @@ -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}");
Expand Down
8 changes: 7 additions & 1 deletion src/GraphQL.Common/GraphQL.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../src.props" />
Expand All @@ -9,11 +9,17 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageIconUrl />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>

<ItemGroup>
<None Include="../../assets/logo.64x64.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>


</Project>
1 change: 1 addition & 0 deletions tests/GraphQL.Integration.Tests/SubscriptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down