Skip to content

Commit da82992

Browse files
committed
add ConnectionParams object
1 parent aa38225 commit da82992

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/GraphQL.Client.Abstractions.Websocket/GraphQLWebSocketRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public string Type
3434
/// <summary>
3535
/// The payload of the websocket request
3636
/// </summary>
37-
public GraphQLRequest Payload
37+
public object Payload
3838
{
39-
get => ContainsKey(PAYLOAD_KEY) ? (GraphQLRequest)this[PAYLOAD_KEY] : null;
39+
get => ContainsKey(PAYLOAD_KEY) ? this[PAYLOAD_KEY] : null;
4040
set => this[PAYLOAD_KEY] = value;
4141
}
4242

src/GraphQL.Client/GraphQLHttpClientOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ public class GraphQLHttpClientOptions
5656
/// Configure additional websocket options (i.e. headers). This will not be invoked on Windows 7 when targeting .NET Framework 4.x.
5757
/// </summary>
5858
public Action<ClientWebSocketOptions> ConfigureWebsocketOptions { get; set; } = options => { };
59+
60+
/// <summary>
61+
/// The `ConnectionParams` object sent with the GQL_CONNECTION_INIT message on establishing a websocket connection.
62+
/// See https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_init.
63+
/// </summary>
64+
public object? WebSocketConnectionParams { get; set; } = null;
5965
}
6066
}

src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
105105
Type = GraphQLWebSocketMessageType.GQL_START,
106106
Payload = request
107107
};
108-
var closeRequest = new GraphQLWebSocketRequest
108+
var stopRequest = new GraphQLWebSocketRequest
109109
{
110110
Id = startRequest.Id,
111111
Type = GraphQLWebSocketMessageType.GQL_STOP
@@ -114,7 +114,7 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
114114
{
115115
Id = startRequest.Id,
116116
Type = GraphQLWebSocketMessageType.GQL_CONNECTION_INIT,
117-
Payload = new GraphQLRequest()
117+
Payload = Options.WebSocketConnectionParams
118118
};
119119

120120
var observable = Observable.Create<GraphQLResponse<TResponse>>(o =>
@@ -179,8 +179,8 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
179179

180180
try
181181
{
182-
Debug.WriteLine($"sending close message on subscription {startRequest.Id}");
183-
await QueueWebSocketRequest(closeRequest);
182+
Debug.WriteLine($"sending stop message on subscription {startRequest.Id}");
183+
await QueueWebSocketRequest(stopRequest);
184184
}
185185
// do not break on disposing
186186
catch (OperationCanceledException) { }

0 commit comments

Comments
 (0)