diff --git a/src/GraphQL.Client/GraphQLHttpClient.cs b/src/GraphQL.Client/GraphQLHttpClient.cs index fb95a963..a0b20c5d 100644 --- a/src/GraphQL.Client/GraphQLHttpClient.cs +++ b/src/GraphQL.Client/GraphQLHttpClient.cs @@ -11,7 +11,7 @@ public class GraphQLHttpClient : IGraphQLClient, IDisposable private readonly Lazy _lazyHttpWebSocket; private GraphQLHttpWebSocket GraphQlHttpWebSocket => _lazyHttpWebSocket.Value; - private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); + private readonly CancellationTokenSource _cancellationTokenSource = new(); private readonly bool _disposeHttpClient = false; @@ -42,14 +42,17 @@ public class GraphQLHttpClient : IGraphQLClient, IDisposable #region Constructors - public GraphQLHttpClient(string endPoint, IGraphQLWebsocketJsonSerializer serializer) : this(new Uri(endPoint), serializer) { } + public GraphQLHttpClient(string endPoint, IGraphQLWebsocketJsonSerializer serializer) + : this(new Uri(endPoint), serializer) { } - public GraphQLHttpClient(Uri endPoint, IGraphQLWebsocketJsonSerializer serializer) : this(o => o.EndPoint = endPoint, serializer) { } + public GraphQLHttpClient(Uri endPoint, IGraphQLWebsocketJsonSerializer serializer) + : this(o => o.EndPoint = endPoint, serializer) { } - public GraphQLHttpClient(Action configure, IGraphQLWebsocketJsonSerializer serializer) : this(configure.New(), serializer) { } + public GraphQLHttpClient(Action configure, IGraphQLWebsocketJsonSerializer serializer) + : this(configure.New(), serializer) { } - public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer) : this( - options, serializer, new HttpClient(options.HttpMessageHandler)) + public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer) + : this(options, serializer, new HttpClient(options.HttpMessageHandler)) { // set this flag to dispose the internally created HttpClient when GraphQLHttpClient gets disposed _disposeHttpClient = true; @@ -120,7 +123,7 @@ private async Task> SendHttpRequestAsync(contentStream, cancellationToken).ConfigureAwait(false); return graphQLResponse.ToGraphQLHttpResponse(httpResponseMessage.Headers, httpResponseMessage.StatusCode); @@ -167,7 +170,7 @@ public void Dispose() } private volatile bool _disposed; - private readonly object _disposeLocker = new object(); + private readonly object _disposeLocker = new(); protected virtual void Dispose(bool disposing) { diff --git a/src/GraphQL.Client/GraphQLHttpClientOptions.cs b/src/GraphQL.Client/GraphQLHttpClientOptions.cs index 74cd6c08..acbdfaab 100644 --- a/src/GraphQL.Client/GraphQLHttpClientOptions.cs +++ b/src/GraphQL.Client/GraphQLHttpClientOptions.cs @@ -1,3 +1,4 @@ +using System.Net; using System.Net.Http.Headers; using System.Net.WebSockets; @@ -16,7 +17,7 @@ public class GraphQLHttpClientOptions /// /// The GraphQL EndPoint to be used for websocket connections /// - public Uri? WebSocketEndPoint { get; set; } = null; + public Uri? WebSocketEndPoint { get; set; } /// /// The that is going to be used @@ -50,12 +51,17 @@ public class GraphQLHttpClientOptions Task.FromResult(request is GraphQLHttpRequest graphQLHttpRequest ? graphQLHttpRequest : new GraphQLHttpRequest(request)); /// - /// This callback is called after successfully establishing a websocket connection but before any regular request is made. + /// Delegate to determine if GraphQL response may be properly deserialized into . + /// + public Func IsValidResponseToDeserialize { get; set; } = r => r.IsSuccessStatusCode || r.StatusCode == HttpStatusCode.BadRequest; + + /// + /// This callback is called after successfully establishing a websocket connection but before any regular request is made. /// public Func OnWebsocketConnected { get; set; } = client => Task.CompletedTask; /// - /// Configure additional websocket options (i.e. headers). This will not be invoked on Windows 7 when targeting .NET Framework 4.x. + /// Configure additional websocket options (i.e. headers). This will not be invoked on Windows 7 when targeting .NET Framework 4.x. /// public Action ConfigureWebsocketOptions { get; set; } = options => { };