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
2 changes: 1 addition & 1 deletion .github/workflows/branches-windows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Branch workflow
on:
on:
push:
branches-ignore:
- '**'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
.vs/
.vscode/
bin/
obj/
*.user
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GraphQL.Client.Abstractions.Websocket
public interface IGraphQLWebsocketJsonSerializer: IGraphQLJsonSerializer {
byte[] SerializeToBytes(GraphQLWebSocketRequest request);

Task<WebsocketResponseWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream);
Task<WebsocketMessageWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream);
GraphQLWebSocketResponse<GraphQLResponse<TResponse>> DeserializeToWebsocketResponse<TResponse>(byte[] bytes);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.Serialization;

namespace GraphQL.Client.Abstractions.Websocket {
public class WebsocketResponseWrapper : GraphQLWebSocketResponse {
public class WebsocketMessageWrapper : GraphQLWebSocketResponse {

[IgnoreDataMember]
public byte[] MessageBytes { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
#region Private Methods

private async Task<GraphQLResponse<TResponse>> ExecuteQueryAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken) {
var executionResult = await ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
return await ExecutionResultToGraphQLResponse<TResponse>(executionResult, cancellationToken).ConfigureAwait(false);
var executionResult = await ExecuteAsync(request, cancellationToken);
return await ExecutionResultToGraphQLResponse<TResponse>(executionResult, cancellationToken);
}
private async Task<IObservable<GraphQLResponse<TResponse>>> ExecuteSubscriptionAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken = default) {
var result = await ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
var result = await ExecuteAsync(request, cancellationToken);
return ((SubscriptionExecutionResult)result).Streams?.Values.SingleOrDefault()?
.SelectMany(executionResult => Observable.FromAsync(token => ExecutionResultToGraphQLResponse<TResponse>(executionResult, token)));
}
Expand All @@ -100,7 +100,7 @@ private async Task<ExecutionResult> ExecuteAsync(GraphQLRequest request, Cancell
options.Query = request.Query;
options.Inputs = inputs;
options.CancellationToken = cancellationToken;
}).ConfigureAwait(false);
});

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public byte[] SerializeToBytes(Abstractions.Websocket.GraphQLWebSocketRequest re
return Encoding.UTF8.GetBytes(json);
}

public Task<WebsocketResponseWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream) {
return DeserializeFromUtf8Stream<WebsocketResponseWrapper>(stream);
public Task<WebsocketMessageWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream) {
return DeserializeFromUtf8Stream<WebsocketMessageWrapper>(stream);
}

public GraphQLWebSocketResponse<GraphQLResponse<TResponse>> DeserializeToWebsocketResponse<TResponse>(byte[] bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public byte[] SerializeToBytes(Abstractions.Websocket.GraphQLWebSocketRequest re
return JsonSerializer.SerializeToUtf8Bytes(new GraphQLWebSocketRequest(request), Options);
}

public Task<WebsocketResponseWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream) {
return JsonSerializer.DeserializeAsync<WebsocketResponseWrapper>(stream, Options).AsTask();
public Task<WebsocketMessageWrapper> DeserializeToWebsocketResponseWrapperAsync(Stream stream) {
return JsonSerializer.DeserializeAsync<WebsocketMessageWrapper>(stream, Options).AsTask();
}

public GraphQLWebSocketResponse<GraphQLResponse<TResponse>> DeserializeToWebsocketResponse<TResponse>(byte[] bytes) {
Expand Down
10 changes: 6 additions & 4 deletions src/GraphQL.Client/GraphQLHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.Http;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -65,7 +66,7 @@ public GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClient
/// <inheritdoc />
public Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken = default) {
return Options.UseWebSocketForQueriesAndMutations
? this.graphQlHttpWebSocket.SendRequest<TResponse>(request, this, cancellationToken)
? this.graphQlHttpWebSocket.SendRequest<TResponse>(request, cancellationToken)
: this.SendHttpPostRequestAsync<TResponse>(request, cancellationToken);
}

Expand All @@ -84,7 +85,7 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
if (subscriptionStreams.ContainsKey(key))
return (IObservable<GraphQLResponse<TResponse>>)subscriptionStreams[key];

var observable = graphQlHttpWebSocket.CreateSubscriptionStream<TResponse>(request, this, cancellationToken: cancellationTokenSource.Token);
var observable = graphQlHttpWebSocket.CreateSubscriptionStream<TResponse>(request);

subscriptionStreams.TryAdd(key, observable);
return observable;
Expand All @@ -100,7 +101,7 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
if (subscriptionStreams.ContainsKey(key))
return (IObservable<GraphQLResponse<TResponse>>)subscriptionStreams[key];

var observable = graphQlHttpWebSocket.CreateSubscriptionStream<TResponse>(request, this, exceptionHandler, cancellationTokenSource.Token);
var observable = graphQlHttpWebSocket.CreateSubscriptionStream<TResponse>(request, exceptionHandler);
subscriptionStreams.TryAdd(key, observable);
return observable;
}
Expand Down Expand Up @@ -164,9 +165,10 @@ public void Dispose() {

private void _dispose() {
disposed = true;
Debug.WriteLine($"disposing GraphQLHttpClient on endpoint {Options.EndPoint}");
cancellationTokenSource.Cancel();
this.HttpClient.Dispose();
this.graphQlHttpWebSocket.Dispose();
cancellationTokenSource.Cancel();
cancellationTokenSource.Dispose();
}

Expand Down
Loading