Skip to content

Commit 6e50381

Browse files
committed
Merge branch 'master' of https://github.com/graphql-dotnet/graphql-client into code-cleanup
# Conflicts: # src/GraphQL.Client.Abstractions.Websocket/GraphQL.Client.Abstractions.Websocket.csproj # src/GraphQL.Client.Serializer.SystemTextJson/GraphQL.Client.Serializer.SystemTextJson.csproj # src/GraphQL.Client/GraphQL.Client.csproj # src/GraphQL.Client/GraphQLHttpException.cs # src/GraphQL.Primitives/GraphQL.Primitives.csproj # src/src.props # tests/GraphQL.Client.Serializer.Tests/GraphQL.Client.Serializer.Tests.csproj # tests/GraphQL.Client.Tests.Common/Helpers/ObservableTester.cs # tests/GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj # tests/GraphQL.Integration.Tests/WebsocketTests/Base.cs # tests/GraphQL.Primitives.Tests/GraphQL.Primitives.Tests.csproj
2 parents 51eb801 + 29407e0 commit 6e50381

24 files changed

+833
-527
lines changed

.github/workflows/branches-windows.yml

Lines changed: 0 additions & 78 deletions
This file was deleted.

.github/workflows/branches-ubuntu.yml renamed to .github/workflows/branches.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
name: Branch workflow (Ubuntu)
1+
name: Branch workflow
22
on:
33
push:
44
branches-ignore:
5-
- develop
5+
- master
66
- 'release/**'
77
- 'releases/**'
8+
pull_request:
89
env:
9-
DOTNET_CLI_TELEMETRY_OPTOUT: true
10+
DOTNET_CLI_TELEMETRY_OPTOUT: true
11+
MSBUILDSINGLELOADCONTEXT: 1
1012
jobs:
1113
generateVersionInfo:
1214
name: GenerateVersionInfo
@@ -18,10 +20,10 @@ jobs:
1820
fetch-depth: 0
1921
- name: Restore dotnet tools
2022
run: dotnet tool restore
21-
- name: Fetch complete repository
22-
run: git fetch
23+
- name: Fetch complete repository including tags
24+
run: git fetch --tags --force --prune && git describe
2325
- name: Generate version info from git history
24-
run: dotnet gitversion /output json > gitversion.json
26+
run: dotnet gitversion /output json > gitversion.json && cat gitversion.json
2527
- name: Upload version info file
2628
uses: actions/upload-artifact@v1
2729
with:

.github/workflows/main-windows.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

.github/workflows/main-ubuntu.yml renamed to .github/workflows/master.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
name: Main workflow (Ubuntu)
1+
name: Master workflow
22
on:
33
push:
44
branches:
5-
- develop
5+
- master
66
- 'release/**'
77
- 'releases/**'
88
tags:
99
- v*
1010
- V*
1111
env:
1212
DOTNET_CLI_TELEMETRY_OPTOUT: true
13+
MSBUILDSINGLELOADCONTEXT: 1
14+
1315
jobs:
1416
generateVersionInfo:
1517
name: GenerateVersionInfo
@@ -21,10 +23,10 @@ jobs:
2123
fetch-depth: 0
2224
- name: Restore dotnet tools
2325
run: dotnet tool restore
24-
- name: Fetch complete repository
25-
run: git fetch
26+
- name: Fetch complete repository including tags
27+
run: git fetch --tags --force --prune && git describe
2628
- name: Generate version info from git history
27-
run: dotnet gitversion /output json > gitversion.json
29+
run: dotnet gitversion /output json > gitversion.json && cat gitversion.json
2830
- name: Upload version info file
2931
uses: actions/upload-artifact@v1
3032
with:

GitVersion.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
mode: ContinuousDeployment
2+
branches:
3+
master:
4+
tag: alpha

dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
]
99
},
1010
"gitversion.tool": {
11-
"version": "5.1.3",
11+
"version": "5.2.4",
1212
"commands": [
1313
"dotnet-gitversion"
1414
]

src/GraphQL.Client.Http/Websocket/IGraphQLWebSocketJsonSerializer.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/GraphQL.Client.Serializer.Newtonsoft/MapConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ private Dictionary<string, object> ReadDictionary(JToken element, Dictionary<str
4848
return to;
4949
}
5050

51-
private IEnumerable<object> ReadArray(JToken element)
51+
private IEnumerable<object> ReadArray(JArray element)
5252
{
53-
foreach (var item in element.Values())
53+
foreach (var item in element)
5454
{
5555
if (IsUnsupportedJTokenType(item.Type))
5656
continue;

src/GraphQL.Client/GraphQL.Client.csproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@
1515
<DefineConstants>NETFRAMEWORK</DefineConstants>
1616
</PropertyGroup>
1717

18-
<ItemGroup>
19-
<Compile Remove="GraphQLSerializationExtensions.cs" />
20-
</ItemGroup>
21-
22-
<ItemGroup>
23-
<None Include="GraphQLSerializationExtensions.cs" />
24-
</ItemGroup>
25-
26-
<ItemGroup>
27-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
28-
</ItemGroup>
29-
3018
<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
3119
<PackageReference Include="System.Net.WebSockets.Client.Managed" Version="1.0.22" />
3220
</ItemGroup>

src/GraphQL.Client/GraphQLHttpClient.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Net.Http;
5-
using System.Text;
66
using System.Threading;
77
using System.Threading.Tasks;
88
using GraphQL.Client.Abstractions;
@@ -70,7 +70,7 @@ public async Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(GraphQLR
7070
if (Options.UseWebSocketForQueriesAndMutations)
7171
return await _graphQlHttpWebSocket.SendRequest<TResponse>(request, cancellationToken);
7272

73-
return await SendHttpPostRequestAsync<TResponse>(request, cancellationToken);
73+
return await SendHttpRequestAsync<TResponse>(request, cancellationToken);
7474
}
7575

7676
/// <inheritdoc />
@@ -121,37 +121,33 @@ public IObservable<GraphQLResponse<TResponse>> CreateSubscriptionStream<TRespons
121121

122122
#region Private Methods
123123

124-
private async Task<GraphQLHttpResponse<TResponse>> SendHttpPostRequestAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken = default)
124+
private async Task<GraphQLHttpResponse<TResponse>> SendHttpRequestAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken = default)
125125
{
126126
var preprocessedRequest = await Options.PreprocessRequest(request, this);
127-
using var httpRequestMessage = GenerateHttpRequestMessage(preprocessedRequest);
128-
using var httpResponseMessage = await HttpClient.SendAsync(httpRequestMessage, cancellationToken);
129-
if (!httpResponseMessage.IsSuccessStatusCode)
130-
{
131-
throw new GraphQLHttpException(httpResponseMessage);
132-
}
127+
128+
using var httpRequestMessage = preprocessedRequest.ToHttpRequestMessage(Options, JsonSerializer);
129+
using var httpResponseMessage = await HttpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
133130

134-
var bodyStream = await httpResponseMessage.Content.ReadAsStreamAsync();
135-
var response = await JsonSerializer.DeserializeFromUtf8StreamAsync<TResponse>(bodyStream, cancellationToken);
136-
return response.ToGraphQLHttpResponse(httpResponseMessage.Headers, httpResponseMessage.StatusCode);
137-
}
131+
var contentStream = await httpResponseMessage.Content.ReadAsStreamAsync();
138132

139-
private HttpRequestMessage GenerateHttpRequestMessage(GraphQLRequest request)
140-
{
141-
var message = new HttpRequestMessage(HttpMethod.Post, Options.EndPoint)
133+
if (httpResponseMessage.IsSuccessStatusCode)
142134
{
143-
Content = new StringContent(JsonSerializer.SerializeToString(request), Encoding.UTF8, Options.MediaType)
144-
};
135+
var graphQLResponse = await JsonSerializer.DeserializeFromUtf8StreamAsync<TResponse>(contentStream, cancellationToken);
136+
return graphQLResponse.ToGraphQLHttpResponse(httpResponseMessage.Headers, httpResponseMessage.StatusCode);
137+
}
145138

146-
if (request is GraphQLHttpRequest httpRequest)
147-
httpRequest.PreprocessHttpRequestMessage(message);
139+
// error handling
140+
string content = null;
141+
if (contentStream != null)
142+
using (var sr = new StreamReader(contentStream))
143+
content = await sr.ReadToEndAsync();
148144

149-
return message;
145+
throw new GraphQLHttpRequestException(httpResponseMessage.StatusCode, httpResponseMessage.Headers, content);
150146
}
151147

152148
private Uri GetWebSocketUri()
153149
{
154-
var webSocketSchema = Options.EndPoint.Scheme == "https" ? "wss" : "ws";
150+
string webSocketSchema = Options.EndPoint.Scheme == "https" ? "wss" : "ws";
155151
return new Uri($"{webSocketSchema}://{Options.EndPoint.Host}:{Options.EndPoint.Port}{Options.EndPoint.AbsolutePath}");
156152
}
157153

0 commit comments

Comments
 (0)