Skip to content

Commit 5816b20

Browse files
committed
Use Func instead of static object to configure
1 parent 3b79495 commit 5816b20

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class GraphQLWebSocketRequest : Dictionary<string, object>, IEquatable<Gr
1414
public const string PAYLOAD_KEY = "payload";
1515

1616
/// <summary>
17-
/// The Identifier of the Response
17+
/// The Identifier of the request
1818
/// </summary>
1919
public string Id
2020
{
@@ -34,7 +34,7 @@ public string Type
3434
/// <summary>
3535
/// The payload of the websocket request
3636
/// </summary>
37-
public object Payload
37+
public object? Payload
3838
{
3939
get => TryGetValue(PAYLOAD_KEY, out object value) ? value : null;
4040
set => this[PAYLOAD_KEY] = value;

src/GraphQL.Client/GraphQLHttpClientOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public class GraphQLHttpClientOptions
6161
/// The `ConnectionParams` object sent with the GQL_CONNECTION_INIT message on establishing a websocket connection.
6262
/// See https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_init.
6363
/// </summary>
64-
public object? WebSocketConnectionParams { get; set; } = null;
64+
public Func<object?> SetWebSocketConnectionParams { get; set; } = () => null;
6565
}
6666
}

src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
9898
Observable.Create<GraphQLResponse<TResponse>>(async observer =>
9999
{
100100
Debug.WriteLine($"Create observable thread id: {Thread.CurrentThread.ManagedThreadId}");
101-
await _client.Options.PreprocessRequest(request, _client);
101+
var preprocessedRequest = await _client.Options.PreprocessRequest(request, _client);
102+
102103
var startRequest = new GraphQLWebSocketRequest
103104
{
104105
Id = Guid.NewGuid().ToString("N"),
105106
Type = GraphQLWebSocketMessageType.GQL_START,
106-
Payload = request
107+
Payload = preprocessedRequest
107108
};
108109
var stopRequest = new GraphQLWebSocketRequest
109110
{
@@ -114,7 +115,7 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
114115
{
115116
Id = startRequest.Id,
116117
Type = GraphQLWebSocketMessageType.GQL_CONNECTION_INIT,
117-
Payload = Options.WebSocketConnectionParams
118+
Payload = Options.SetWebSocketConnectionParams()
118119
};
119120

120121
var observable = Observable.Create<GraphQLResponse<TResponse>>(o =>

0 commit comments

Comments
 (0)