Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GraphQL.Client.Abstractions.Websocket {
public enum GraphQLWebsocketConnectionState {
Disconnected,
Connecting,
Connected
}
}
10 changes: 7 additions & 3 deletions src/GraphQL.Client/GraphQLHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -33,6 +32,11 @@ public class GraphQLHttpClient : IGraphQLClient {
/// </summary>
public IObservable<Exception> WebSocketReceiveErrors => graphQlHttpWebSocket.ReceiveErrors;

/// <summary>
/// the websocket connection state
/// </summary>
public IObservable<GraphQLWebsocketConnectionState> WebsocketConnectionState =>
graphQlHttpWebSocket.ConnectionState;

#region Constructors

Expand All @@ -47,15 +51,15 @@ public GraphQLHttpClient(Action<GraphQLHttpClientOptions> configure) : this(conf
public GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClient) {
Options = options;
this.HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
this.graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), Options);
this.graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this);
Options.JsonSerializer = JsonSerializer.EnsureAssigned();
}

public GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClient, IGraphQLWebsocketJsonSerializer serializer) {
Options = options ?? throw new ArgumentNullException(nameof(options));
Options.JsonSerializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
this.HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
this.graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), Options);
this.graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this);
}

#endregion
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQL.Client/GraphQLHttpClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public class GraphQLHttpClientOptions {
/// Request preprocessing function. Can be used i.e. to inject authorization info into a GraphQL request payload.
/// </summary>
public Func<GraphQLRequest, GraphQLHttpClient, Task<GraphQLRequest>> PreprocessRequest { get; set; } = (request, client) => Task.FromResult(request);

/// <summary>
/// This callback is called after successfully establishing a websocket connection but before any regular request is made.
/// </summary>
public Func<GraphQLHttpClient, Task> OnWebsocketConnected { get; set; } = client => Task.CompletedTask;
}
}
Loading