Skip to content

Commit 87dbf3e

Browse files
committed
Create new GraphQLHttpWebSocket instance if needed
1 parent a1a3978 commit 87dbf3e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/GraphQL.Client/GraphQLHttpClient.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace GraphQL.Client.Http
1515
{
1616
public class GraphQLHttpClient : IGraphQLClient
1717
{
18-
private readonly GraphQLHttpWebSocket _graphQlHttpWebSocket;
18+
private readonly GraphQLHttpWebSocket _graphQlHttpWebSocket = null;
1919
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
2020
private readonly ConcurrentDictionary<Tuple<GraphQLRequest, Type>, object> _subscriptionStreams = new ConcurrentDictionary<Tuple<GraphQLRequest, Type>, object>();
2121

@@ -63,7 +63,8 @@ public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJson
6363
if (!HttpClient.DefaultRequestHeaders.UserAgent.Any())
6464
HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version.ToString()));
6565

66-
_graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this);
66+
if (options.UseWebSocketForQueriesAndMutations)
67+
_graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this);
6768
}
6869

6970
#endregion
@@ -186,7 +187,7 @@ protected virtual void Dispose(bool disposing)
186187
Debug.WriteLine($"Disposing GraphQLHttpClient on endpoint {Options.EndPoint}");
187188
_cancellationTokenSource.Cancel();
188189
HttpClient.Dispose();
189-
_graphQlHttpWebSocket.Dispose();
190+
_graphQlHttpWebSocket?.Dispose();
190191
_cancellationTokenSource.Dispose();
191192
}
192193
}

0 commit comments

Comments
 (0)