Skip to content
Merged
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
2 changes: 1 addition & 1 deletion root.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<LangVersion>8.0</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>CS0618;CS1591;CS1701;CS8618;NU5048;NU5105;NU5125</NoWarn>
<NoWarn>CS0618;CS1591;CS1701;CS8618;CS8632;NU5048;NU5105;NU5125</NoWarn>
<Nullable>annotations</Nullable>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
Expand Down
21 changes: 17 additions & 4 deletions src/GraphQL.Client.Http/GraphQL.Client.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@
<Import Project="../src.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net461</TargetFrameworks>
</PropertyGroup>

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

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net461'">
<DefineConstants>NETFRAMEWORK</DefineConstants>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Dahomey.Json" Version="1.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Text.Json" Version="4.7.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Net.WebSockets.Client.Managed" Version="1.0.22" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/GraphQL.Client.Http/GraphQLHttpClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ public class GraphQLHttpClientOptions {
/// Request preprocessing function. Can be used i.e. to inject authorization info into a GraphQL request payload.
/// </summary>
public Func<GraphQLRequest, GraphQLHttpClient, Task<GraphQLRequest>> PreprocessRequest { get; set; } = (request, client) => Task.FromResult(request);

}
}
20 changes: 15 additions & 5 deletions src/GraphQL.Client.Http/Websocket/GraphQLHttpWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ internal class GraphQLHttpWebSocket : IDisposable {

public WebSocketState WebSocketState => clientWebSocket?.State ?? WebSocketState.None;

#if NETFRAMEWORK
private WebSocket clientWebSocket = null;
#else
private ClientWebSocket clientWebSocket = null;
#endif
private int _connectionAttempt = 0;

public GraphQLHttpWebSocket(Uri webSocketUri, GraphQLHttpClientOptions options) {
Expand Down Expand Up @@ -71,7 +75,7 @@ await this.clientWebSocket.SendAsync(

private readonly object _initializeLock = new object();

#region Private Methods
#region Private Methods

private Task _backOff() {
_connectionAttempt++;
Expand Down Expand Up @@ -103,6 +107,7 @@ public Task InitializeWebSocket() {
//_responseStreamConnection?.Dispose();
clientWebSocket?.Dispose();

#if NETFRAMEWORK
// fix websocket not supported on win 7 using
// https://github.com/PingmanTools/System.Net.WebSockets.Client.Managed
clientWebSocket = SystemClientWebSocket.CreateClientWebSocket();
Expand All @@ -120,7 +125,12 @@ public Task InitializeWebSocket() {
default:
throw new NotSupportedException($"unknown websocket type {clientWebSocket.GetType().Name}");
}

#else
clientWebSocket = new ClientWebSocket();
clientWebSocket.Options.AddSubProtocol("graphql-ws");
clientWebSocket.Options.ClientCertificates = ((HttpClientHandler)_options.HttpMessageHandler).ClientCertificates;
clientWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)_options.HttpMessageHandler).UseDefaultCredentials;
#endif
return InitializeWebSocketTask = _connectAsync(_cancellationTokenSource.Token);
}
}
Expand Down Expand Up @@ -247,9 +257,9 @@ private async Task _closeAsync(CancellationToken cancellationToken = default) {
await this.clientWebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", cancellationToken).ConfigureAwait(false);
}

#endregion
#endregion

#region IDisposable
#region IDisposable

private Task _disposed;
private object _disposedLocker = new object();
Expand All @@ -269,6 +279,6 @@ private async Task DisposeAsync() {
_cancellationTokenSource.Dispose();
Debug.WriteLine($"websocket {clientWebSocket.GetHashCode()} disposed");
}
#endregion
#endregion
}
}
2 changes: 0 additions & 2 deletions src/GraphQL.Client/GraphQL.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
<PackageReference Include="System.Net.WebSockets.Client.Managed" Version="1.0.22" />
<PackageReference Include="System.Reactive" Version="4.1.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
Expand Down