@@ -19,7 +19,7 @@ public class GraphQLWSTransport : IGraphQLTransport
19
19
/// Due to historical reasons this actually is the protocol name used
20
20
/// by the newer protocol.
21
21
/// </summary>
22
- public static string SubProtocol = "graphql-transport-ws" ;
22
+ public const string GraphQLTransportWSProtocol = "graphql-transport-ws" ;
23
23
24
24
public IEndpointConventionBuilder Map ( string pattern , IEndpointRouteBuilder routes ,
25
25
GraphQLRequestDelegate requestDelegate )
@@ -36,10 +36,12 @@ private async Task HandleProtocol(
36
36
WebSocket webSocket ,
37
37
GraphQLRequestDelegate requestPipeline )
38
38
{
39
- var connection = new GraphQLWSConnection ( webSocket , requestPipeline , httpContext ) ;
40
- await connection . Connect ( httpContext . RequestAborted ) ;
41
- }
39
+ var handler = new WebSocketTransportHandler (
40
+ requestPipeline ,
41
+ httpContext ) ;
42
42
43
+ await handler . Handle ( webSocket ) ;
44
+ }
43
45
44
46
private RequestDelegate ProcessRequest ( GraphQLRequestDelegate pipeline )
45
47
{
@@ -56,19 +58,28 @@ await httpContext.Response.WriteAsJsonAsync(new ProblemDetails
56
58
return ;
57
59
}
58
60
59
- if ( httpContext . WebSockets . WebSocketRequestedProtocols ? . Contains ( SubProtocol ) == false )
61
+ if ( httpContext . WebSockets . WebSocketRequestedProtocols ? . Contains ( EchoProtocol . Protocol ) == true )
62
+ {
63
+ using WebSocket echoWebSocket = await httpContext . WebSockets
64
+ . AcceptWebSocketAsync ( EchoProtocol . Protocol ) ;
65
+
66
+ await EchoProtocol . Run ( echoWebSocket ) ;
67
+ return ;
68
+ }
69
+
70
+ if ( httpContext . WebSockets . WebSocketRequestedProtocols ? . Contains ( GraphQLTransportWSProtocol ) == false )
60
71
{
61
72
httpContext . Response . StatusCode = StatusCodes . Status400BadRequest ;
62
73
await httpContext . Response . WriteAsJsonAsync ( new ProblemDetails
63
74
{
64
- Detail = $ "Request does not contain sub-protocol '{ SubProtocol } '."
75
+ Detail = $ "Request does not contain sub-protocol '{ GraphQLTransportWSProtocol } '."
65
76
} ) ;
66
77
67
78
return ;
68
79
}
69
80
70
- WebSocket webSocket = await httpContext . WebSockets
71
- . AcceptWebSocketAsync ( SubProtocol ) ;
81
+ using WebSocket webSocket = await httpContext . WebSockets
82
+ . AcceptWebSocketAsync ( GraphQLTransportWSProtocol ) ;
72
83
73
84
await HandleProtocol ( httpContext , webSocket , pipeline ) ;
74
85
} ;
0 commit comments