Skip to content

Commit 70d53fa

Browse files
authored
Added a utility to communicate with graphql-ws (#4820)
1 parent 81ba508 commit 70d53fa

File tree

69 files changed

+2172
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2172
-191
lines changed

.build/Build.Environment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ partial class Build
77
const string Net50 = "net5.0";
88
const string Net60 = "net6.0";
99

10-
readonly int DegreeOfParallelism = System.Environment.ProcessorCount * 3;
10+
readonly int DegreeOfParallelism = 2;
1111

1212
AbsolutePath SourceDirectory => RootDirectory / "src";
1313
AbsolutePath AllSolutionFile => SourceDirectory / "All.sln";

.build/Build.Sonar.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
using Nuke.Common.Tooling;
33
using Nuke.Common.Tools.DotNet;
44
using Nuke.Common.Tools.SonarScanner;
5+
using Serilog;
56
using static System.IO.Path;
67
using static Nuke.Common.Tools.DotNet.DotNetTasks;
78
using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks;
89
using static Helpers;
9-
using Serilog;
1010

1111
partial class Build
1212
{
@@ -89,7 +89,7 @@ SonarScannerBeginSettings SonarBeginPrSettings(SonarScannerBeginSettings setting
8989
.Add("/d:sonar.pullrequest.key={0}", GitHubPRNumber)
9090
.Add("/d:sonar.pullrequest.branch={0}", GitHubHeadRef)
9191
.Add("/d:sonar.pullrequest.base={0}", GitHubBaseRef)
92-
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"))
92+
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "false"))
9393
.SetFramework(Net50);
9494

9595
SonarScannerBeginSettings SonarBeginFullSettings(SonarScannerBeginSettings settings) =>
@@ -108,7 +108,7 @@ SonarScannerBeginSettings SonarBeginBaseSettings(SonarScannerBeginSettings setti
108108
.AddSourceExclusions("**/Generated/**/*.*,**/*.Designer.cs,**/*.generated.cs,**/*.js,**/*.html,**/*.css,**/Sample/**/*.*,**/Samples.*/**/*.*,**/*Tools.*/**/*.*,**/Program.Dev.cs, **/Program.cs,**/*.ts,**/*.tsx,**/*EventSource.cs,**/*EventSources.cs,**/*.Samples.cs,**/*Tests.*/**/*.*,**/*Test.*/**/*.*")
109109
.SetProcessArgumentConfigurator(t => t
110110
.Add("/o:{0}", "chillicream")
111-
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"));
111+
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "false"));
112112

113113
SonarScannerBeginSettings SonarBaseSettings(SonarScannerBeginSettings settings) =>
114114
settings

src/HotChocolate/AspNetCore/HotChocolate.AspNetCore.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.AspNetCore.Aut
4747
EndProject
4848
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.AspNetCore.Authorization.Tests", "test\AspNetCore.Authorization.Tests\HotChocolate.AspNetCore.Authorization.Tests.csproj", "{CBADBC3F-FACC-424C-8E7D-28A029F5C238}"
4949
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Transport.Sockets", "src\Transport.Sockets\HotChocolate.Transport.Sockets.csproj", "{8E85603A-E36A-4133-BF04-7734BCD02D1F}"
51+
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Transport.Sockets.Client", "src\Transport.Sockets.Client\HotChocolate.Transport.Sockets.Client.csproj", "{1284182A-3F75-4AF3-A1EE-7D7085C3545A}"
53+
EndProject
5054
Global
5155
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5256
Debug|Any CPU = Debug|Any CPU
@@ -249,6 +253,30 @@ Global
249253
{CBADBC3F-FACC-424C-8E7D-28A029F5C238}.Release|x64.Build.0 = Release|Any CPU
250254
{CBADBC3F-FACC-424C-8E7D-28A029F5C238}.Release|x86.ActiveCfg = Release|Any CPU
251255
{CBADBC3F-FACC-424C-8E7D-28A029F5C238}.Release|x86.Build.0 = Release|Any CPU
256+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
257+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
258+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x64.ActiveCfg = Debug|Any CPU
259+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x64.Build.0 = Debug|Any CPU
260+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x86.ActiveCfg = Debug|Any CPU
261+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x86.Build.0 = Debug|Any CPU
262+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
263+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|Any CPU.Build.0 = Release|Any CPU
264+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x64.ActiveCfg = Release|Any CPU
265+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x64.Build.0 = Release|Any CPU
266+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x86.ActiveCfg = Release|Any CPU
267+
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x86.Build.0 = Release|Any CPU
268+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
269+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|Any CPU.Build.0 = Debug|Any CPU
270+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x64.ActiveCfg = Debug|Any CPU
271+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x64.Build.0 = Debug|Any CPU
272+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x86.ActiveCfg = Debug|Any CPU
273+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x86.Build.0 = Debug|Any CPU
274+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|Any CPU.ActiveCfg = Release|Any CPU
275+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|Any CPU.Build.0 = Release|Any CPU
276+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x64.ActiveCfg = Release|Any CPU
277+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x64.Build.0 = Release|Any CPU
278+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x86.ActiveCfg = Release|Any CPU
279+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x86.Build.0 = Release|Any CPU
252280
EndGlobalSection
253281
GlobalSection(SolutionProperties) = preSolution
254282
HideSolutionNode = FALSE
@@ -270,6 +298,8 @@ Global
270298
{9957A20C-4DCC-4643-B97D-ACF00D75C702} = {8A75EB03-3E25-4819-AE7D-1159D5AED817}
271299
{3DA60297-97CB-4712-89C6-F71EB75F98EA} = {2E2070DF-95C2-48F2-A8DF-7FE3734817ED}
272300
{CBADBC3F-FACC-424C-8E7D-28A029F5C238} = {936FF2E5-6576-4257-A7A3-F2093D44E6CD}
301+
{8E85603A-E36A-4133-BF04-7734BCD02D1F} = {2E2070DF-95C2-48F2-A8DF-7FE3734817ED}
302+
{1284182A-3F75-4AF3-A1EE-7D7085C3545A} = {2E2070DF-95C2-48F2-A8DF-7FE3734817ED}
273303
EndGlobalSection
274304
GlobalSection(ExtensibilityGlobals) = postSolution
275305
SolutionGuid = {EAA92712-961A-4595-82AD-C031830477CC}

src/HotChocolate/AspNetCore/src/AspNetCore/HotChocolate.AspNetCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\..\Core\src\Core\HotChocolate.Core.csproj" />
1717
<ProjectReference Include="..\..\..\Core\src\Types.Scalars.Upload\HotChocolate.Types.Scalars.Upload.csproj" />
18+
<ProjectReference Include="..\Transport.Sockets\HotChocolate.Transport.Sockets.csproj" />
1819
</ItemGroup>
1920

2021
<ItemGroup>

src/HotChocolate/AspNetCore/src/AspNetCore/Subscriptions/Constants.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/HotChocolate/AspNetCore/src/AspNetCore/Subscriptions/ISocketConnection.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Buffers;
22
using HotChocolate.AspNetCore.Subscriptions.Protocols;
3+
using HotChocolate.Transport.Sockets;
34
using Microsoft.AspNetCore.Http;
45

56
namespace HotChocolate.AspNetCore.Subscriptions;
@@ -8,18 +9,13 @@ namespace HotChocolate.AspNetCore.Subscriptions;
89
/// The socket connection represent an accepted connection with a socket
910
/// where the protocol is already negotiated.
1011
/// </summary>
11-
public interface ISocketConnection : IHasContextData, IDisposable
12+
public interface ISocketConnection : ISocket, IHasContextData, IDisposable
1213
{
1314
/// <summary>
1415
/// Gets access to the HTTP Context.
1516
/// </summary>
1617
HttpContext HttpContext { get; }
1718

18-
/// <summary>
19-
/// Specifies if the connection is closed.
20-
/// </summary>
21-
bool IsClosed { get; }
22-
2319
/// <summary>
2420
/// Gets access to the request scoped service provider.
2521
/// </summary>
@@ -48,19 +44,6 @@ ValueTask SendAsync(
4844
ReadOnlyMemory<byte> message,
4945
CancellationToken cancellationToken = default);
5046

51-
/// <summary>
52-
/// Reads a message from the client.
53-
/// </summary>
54-
/// <param name="writer">
55-
/// The writer to which the message is written to.
56-
/// </param>
57-
/// <param name="cancellationToken">
58-
/// The cancellation token.
59-
/// </param>
60-
ValueTask ReceiveAsync(
61-
IBufferWriter<byte> writer,
62-
CancellationToken cancellationToken = default);
63-
6447
/// <summary>
6548
/// Closes the connection with the client.
6649
/// </summary>

src/HotChocolate/AspNetCore/src/AspNetCore/Subscriptions/MessageReceiver.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/HotChocolate/AspNetCore/src/AspNetCore/Subscriptions/PingPongJob.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,21 @@ public PingPongJob(ISocketSession session, GraphQLSocketOptions options)
1414
_options = options;
1515
}
1616

17-
public void Begin(CancellationToken cancellationToken)
18-
=> Task.Factory.StartNew(
19-
() => KeepConnectionAliveAsync(cancellationToken),
20-
cancellationToken,
21-
TaskCreationOptions.LongRunning,
22-
TaskScheduler.Default);
23-
24-
private async Task KeepConnectionAliveAsync(CancellationToken ct)
17+
public async Task RunAsync(CancellationToken cancellationToken)
2518
{
2619
ISocketConnection connection = _session.Connection;
2720
IProtocolHandler protocolHandler = _session.Protocol;
2821

2922
try
3023
{
3124
// first we will wait for a connection to be established
32-
await Task.Delay(_options.ConnectionInitializationTimeout, ct);
25+
await Task.Delay(_options.ConnectionInitializationTimeout, cancellationToken);
3326

3427
// if after the timeout no connection initialization was send by the client we will
3528
// close the connection.
3629
if (!connection.ContextData.ContainsKey(ConnectionContextKeys.Connected))
3730
{
38-
await _session.Protocol.OnConnectionInitTimeoutAsync(_session, ct);
31+
await _session.Protocol.OnConnectionInitTimeoutAsync(_session, cancellationToken);
3932
return;
4033
}
4134

@@ -45,18 +38,18 @@ private async Task KeepConnectionAliveAsync(CancellationToken ct)
4538
{
4639
TimeSpan interval = _options.KeepAliveInterval.Value;
4740

48-
while (!connection.IsClosed && !ct.IsCancellationRequested)
41+
while (!connection.IsClosed && !cancellationToken.IsCancellationRequested)
4942
{
50-
await Task.Delay(interval, ct);
43+
await Task.Delay(interval, cancellationToken);
5144

5245
if (!connection.IsClosed)
5346
{
54-
await protocolHandler.SendKeepAliveMessageAsync(_session, ct);
47+
await protocolHandler.SendKeepAliveMessageAsync(_session, cancellationToken);
5548
}
5649
}
5750
}
5851
}
59-
catch (OperationCanceledException) when (ct.IsCancellationRequested)
52+
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
6053
{
6154
// the message processing was canceled.
6255
}

src/HotChocolate/AspNetCore/src/AspNetCore/Subscriptions/Protocols/Apollo/ApolloSubscriptionProtocolHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using HotChocolate.Utilities;
77
using static HotChocolate.AspNetCore.Properties.AspNetCoreResources;
88
using static HotChocolate.AspNetCore.Subscriptions.ConnectionContextKeys;
9-
using static HotChocolate.AspNetCore.Subscriptions.ProtocolNames;
9+
using static HotChocolate.Transport.Sockets.WellKnownProtocols;
1010
using static HotChocolate.AspNetCore.Subscriptions.Protocols.MessageUtilities;
1111
using static HotChocolate.AspNetCore.Subscriptions.Protocols.Apollo.MessageProperties;
1212
using static HotChocolate.Language.Utf8GraphQLRequestParser;

src/HotChocolate/AspNetCore/src/AspNetCore/Subscriptions/Protocols/Apollo/Utf8MessageBodies.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ internal static class Utf8MessageBodies
44
{
55
private static readonly byte[] _keepAlive =
66
{
7+
(byte)'{',
8+
(byte)'"',
9+
(byte)'t',
10+
(byte)'y',
11+
(byte)'p',
12+
(byte)'e',
13+
(byte)'"',
14+
(byte)':',
15+
(byte)'"',
716
(byte)'k',
8-
(byte)'a'
17+
(byte)'a',
18+
(byte)'"',
19+
(byte)'}'
920
};
1021

1122
public static ReadOnlyMemory<byte> KeepAlive => _keepAlive;

0 commit comments

Comments
 (0)