Skip to content

Commit 4cfc36d

Browse files
authored
Use new (de)serialization code from main project (#716)
1 parent 2d3740c commit 4cfc36d

File tree

67 files changed

+269
-975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+269
-975
lines changed

GraphQL.Server.sln

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{5C07
5050
EndProject
5151
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ui.Altair", "src\Ui.Altair\Ui.Altair.csproj", "{008CFAAB-64B6-4948-99FA-E8735CA7E81A}"
5252
EndProject
53-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transports.AspNetCore.NewtonsoftJson", "src\Transports.AspNetCore.NewtonsoftJson\Transports.AspNetCore.NewtonsoftJson.csproj", "{24975BA5-46B0-4E3A-8703-9599483138B8}"
54-
EndProject
55-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transports.AspNetCore.SystemTextJson", "src\Transports.AspNetCore.SystemTextJson\Transports.AspNetCore.SystemTextJson.csproj", "{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}"
56-
EndProject
57-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Serialization", "Serialization", "{27A37AAB-90F9-4F1E-B1BB-AAF5A90D97AE}"
58-
EndProject
5953
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "src\Benchmarks\Benchmarks.csproj", "{C1FCE2C8-F6EF-48DA-ADD8-9159516D03DA}"
6054
EndProject
6155
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{592C7A03-4F0C-40C2-86F9-C7A4E03504A7}"
@@ -147,14 +141,6 @@ Global
147141
{008CFAAB-64B6-4948-99FA-E8735CA7E81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
148142
{008CFAAB-64B6-4948-99FA-E8735CA7E81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
149143
{008CFAAB-64B6-4948-99FA-E8735CA7E81A}.Release|Any CPU.Build.0 = Release|Any CPU
150-
{24975BA5-46B0-4E3A-8703-9599483138B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
151-
{24975BA5-46B0-4E3A-8703-9599483138B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
152-
{24975BA5-46B0-4E3A-8703-9599483138B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
153-
{24975BA5-46B0-4E3A-8703-9599483138B8}.Release|Any CPU.Build.0 = Release|Any CPU
154-
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155-
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Debug|Any CPU.Build.0 = Debug|Any CPU
156-
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Release|Any CPU.ActiveCfg = Release|Any CPU
157-
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Release|Any CPU.Build.0 = Release|Any CPU
158144
{C1FCE2C8-F6EF-48DA-ADD8-9159516D03DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
159145
{C1FCE2C8-F6EF-48DA-ADD8-9159516D03DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
160146
{C1FCE2C8-F6EF-48DA-ADD8-9159516D03DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -186,8 +172,6 @@ Global
186172
{741DEEE6-FD0B-4F99-8A6F-43584B3E8D5F} = {BBD07745-C962-4D2D-B302-6DA1BCC2FF43}
187173
{62E7B30D-CB34-45EA-A410-2CAE127385D7} = {BBD07745-C962-4D2D-B302-6DA1BCC2FF43}
188174
{008CFAAB-64B6-4948-99FA-E8735CA7E81A} = {EFEC04E1-42DD-4689-B808-5C630A9AA59D}
189-
{24975BA5-46B0-4E3A-8703-9599483138B8} = {27A37AAB-90F9-4F1E-B1BB-AAF5A90D97AE}
190-
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47} = {27A37AAB-90F9-4F1E-B1BB-AAF5A90D97AE}
191175
{C1FCE2C8-F6EF-48DA-ADD8-9159516D03DA} = {BBD07745-C962-4D2D-B302-6DA1BCC2FF43}
192176
{17945A3F-4C80-43B3-BBD7-6FE0EA107799} = {592C7A03-4F0C-40C2-86F9-C7A4E03504A7}
193177
{9F1A96BC-FF87-427F-8284-5A0670CA596C} = {BBD07745-C962-4D2D-B302-6DA1BCC2FF43}

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Provides the following packages:
2929
| GraphQL.Server.All | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.All)](https://www.nuget.org/packages/GraphQL.Server.All) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.All)](https://www.nuget.org/packages/GraphQL.Server.All) |
3030
| GraphQL.Server.Core | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Core)](https://www.nuget.org/packages/GraphQL.Server.Core) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Core)](https://www.nuget.org/packages/GraphQL.Server.Core) |
3131
| GraphQL.Server.Transports.AspNetCore | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.AspNetCore)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Transports.AspNetCore)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore) |
32-
| GraphQL.Server.Transports.AspNetCore.NewtonsoftJson | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.AspNetCore.NewtonsoftJson)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore.NewtonsoftJson) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Transports.AspNetCore.NewtonsoftJson)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore.NewtonsoftJson) |
33-
| GraphQL.Server.Transports.AspNetCore.SystemTextJson | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.AspNetCore.SystemTextJson)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore.SystemTextJson) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Transports.AspNetCore.SystemTextJson)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore.SystemTextJson) |
3432
| GraphQL.Server.Transports.Subscriptions.Abstractions | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.Subscriptions.Abstractions)](https://www.nuget.org/packages/GraphQL.Server.Transports.Subscriptions.Abstractions) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Transports.Subscriptions.Abstractions)](https://www.nuget.org/packages/GraphQL.Server.Transports.Subscriptions.Abstractions) |
3533
| GraphQL.Server.Transports.Subscriptions.WebSockets <br/> *formerly known as `GraphQL.Server.Transports.WebSockets`* | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.Subscriptions.WebSockets)](https://www.nuget.org/packages/GraphQL.Server.Transports.Subscriptions.WebSockets) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Transports.Subscriptions.WebSockets)](https://www.nuget.org/packages/GraphQL.Server.Transports.Subscriptions.WebSockets) |
3634
| GraphQL.Server.Ui.Altair | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Ui.Altair)](https://www.nuget.org/packages/GraphQL.Server.Ui.Altair) | [![Nuget](https://img.shields.io/nuget/v/GraphQL.Server.Ui.Altair)](https://www.nuget.org/packages/GraphQL.Server.Ui.Altair) |
@@ -56,21 +54,21 @@ For just the HTTP middleware:
5654
> dotnet add package GraphQL.Server.Transports.AspNetCore
5755
```
5856

59-
The HTTP middleware needs an `IGraphQLRequestDeserializer` implementation.
57+
The HTTP middleware needs an `IGraphQLTextSerializer` implementation.
6058

6159
.NET Core 3+:
6260

6361
```
64-
> dotnet add package GraphQL.Server.Transports.AspNetCore.SystemTextJson
62+
> dotnet add package GraphQL.SystemTextJson
6563
```
6664

6765
Legacy (prior to .NET Core 3):
6866

6967
```
70-
> dotnet add package GraphQL.Server.Transports.AspNetCore.NewtonsoftJson
68+
> dotnet add package GraphQL.NewtonsoftJson
7169
```
7270

73-
Or you can use your own `IGraphQLRequestDeserializer` implementation.
71+
Or you can use your own `IGraphQLTextSerializer` implementation.
7472

7573
For more information on how to migrate from `Newtonsoft.Json` to `System.Text.Json` see
7674
[this article](https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to).

samples/Samples.Server/GraphQLHttpMiddlewareWithLogs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class GraphQLHttpMiddlewareWithLogs<TSchema> : GraphQLHttpMiddleware<TSch
1717
public GraphQLHttpMiddlewareWithLogs(
1818
ILogger<GraphQLHttpMiddleware<TSchema>> logger,
1919
RequestDelegate next,
20-
IGraphQLRequestDeserializer requestDeserializer)
20+
IGraphQLTextSerializer requestDeserializer)
2121
: base(next, requestDeserializer)
2222
{
2323
_logger = logger;

samples/Samples.Server/Samples.Server.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
<ItemGroup>
1212
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
1313
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
14-
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-452" />
14+
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-457" />
15+
<PackageReference Include="GraphQL.SystemTextJson" Version="5.0.0-preview-457" />
1516
</ItemGroup>
1617

1718
<ItemGroup>
19+
<ProjectReference Include="..\..\src\Transports.AspNetCore\Transports.AspNetCore.csproj" />
1820
<ProjectReference Include="..\..\src\Authorization.AspNetCore\Authorization.AspNetCore.csproj" />
19-
<ProjectReference Include="..\..\src\Transports.AspNetCore.SystemTextJson\Transports.AspNetCore.SystemTextJson.csproj" />
2021
<ProjectReference Include="..\..\src\Transports.Subscriptions.WebSockets\Transports.Subscriptions.WebSockets.csproj" />
2122
<ProjectReference Include="..\..\src\Ui.GraphiQL\Ui.GraphiQL.csproj" />
2223
<ProjectReference Include="..\..\src\Ui.Playground\Ui.Playground.csproj" />

samples/Samples.Server/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using GraphQL.Server.Ui.GraphiQL;
1111
using GraphQL.Server.Ui.Playground;
1212
using GraphQL.Server.Ui.Voyager;
13+
using GraphQL.SystemTextJson;
1314
using Microsoft.AspNetCore.Builder;
1415
using Microsoft.AspNetCore.Hosting;
1516
using Microsoft.Extensions.Configuration;

samples/Samples.Server/StartupWithRouting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Extensions.Hosting;
1616
using Microsoft.Extensions.Logging;
1717
using GraphQL.MicrosoftDI;
18+
using GraphQL.SystemTextJson;
1819

1920
namespace GraphQL.Samples.Server
2021
{

src/All/All.csproj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<ItemGroup>
1212
<ProjectReference Include="..\Authorization.AspNetCore\Authorization.AspNetCore.csproj" />
1313
<ProjectReference Include="..\Core\Core.csproj" />
14-
<ProjectReference Include="..\Transports.AspNetCore.NewtonsoftJson\Transports.AspNetCore.NewtonsoftJson.csproj" />
15-
<ProjectReference Include="..\Transports.AspNetCore.SystemTextJson\Transports.AspNetCore.SystemTextJson.csproj" />
1614
<ProjectReference Include="..\Transports.AspNetCore\Transports.AspNetCore.csproj" />
1715
<ProjectReference Include="..\Transports.Subscriptions.Abstractions\Transports.Subscriptions.Abstractions.csproj" />
1816
<ProjectReference Include="..\Transports.Subscriptions.WebSockets\Transports.Subscriptions.WebSockets.csproj" />
@@ -21,9 +19,9 @@
2119
<ProjectReference Include="..\Ui.Playground\Ui.Playground.csproj" />
2220
<ProjectReference Include="..\Ui.Voyager\Ui.Voyager.csproj" />
2321

24-
<PackageReference Include="GraphQL.MemoryCache" Version="5.0.0-preview-452" />
25-
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-452" />
26-
<PackageReference Include="GraphQL.SystemReactive" Version="5.0.0-preview-452" />
22+
<PackageReference Include="GraphQL.MemoryCache" Version="5.0.0-preview-457" />
23+
<PackageReference Include="GraphQL.MicrosoftDI" Version="5.0.0-preview-457" />
24+
<PackageReference Include="GraphQL.SystemReactive" Version="5.0.0-preview-457" />
2725
</ItemGroup>
2826

2927
</Project>

src/Benchmarks/Benchmarks.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
1313
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.19" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
1414
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" Condition="'$(TargetFramework)' == 'net5'" />
15+
<PackageReference Include="GraphQL.SystemTextJson" Version="5.0.0-preview-457" />
16+
<PackageReference Include="GraphQL.NewtonsoftJson" Version="5.0.0-preview-457" />
1517
</ItemGroup>
1618

1719
<ItemGroup>
1820
<Compile Include="..\..\tests\Samples.Server.Tests\Serializer.cs" Link="Shared\Serializer.cs" />
1921
</ItemGroup>
2022

21-
<ItemGroup>
22-
<ProjectReference Include="..\Transports.AspNetCore.NewtonsoftJson\Transports.AspNetCore.NewtonsoftJson.csproj" />
23-
<ProjectReference Include="..\Transports.AspNetCore.SystemTextJson\Transports.AspNetCore.SystemTextJson.csproj" />
24-
</ItemGroup>
25-
2623
</Project>

src/Benchmarks/Benchmarks/DeserializeFromJsonBodyBenchmark.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
using System.Text;
33
using System.Threading.Tasks;
44
using BenchmarkDotNet.Attributes;
5-
using GraphQL.Server.Transports.AspNetCore;
6-
using GraphQL.SystemTextJson;
7-
using Microsoft.AspNetCore.Http;
8-
using Microsoft.AspNetCore.Http.Features;
9-
using NsjDeserializer = GraphQL.Server.Transports.AspNetCore.NewtonsoftJson.GraphQLRequestDeserializer;
10-
using StjDeserializer = GraphQL.Server.Transports.AspNetCore.SystemTextJson.GraphQLRequestDeserializer;
5+
using GraphQL.Transport;
6+
using NsjDeserializer = GraphQL.NewtonsoftJson.GraphQLSerializer;
7+
using StjDeserializer = GraphQL.SystemTextJson.GraphQLSerializer;
118

129
namespace GraphQL.Server.Benchmarks
1310
{
@@ -17,8 +14,8 @@ public class DeserializeFromJsonBodyBenchmark
1714
{
1815
private NsjDeserializer _nsjDeserializer;
1916
private StjDeserializer _stjDeserializer;
20-
private HttpRequest _httpRequest;
21-
private HttpRequest _httpRequest2;
17+
private Stream _httpRequestBody;
18+
private Stream _httpRequestBody2;
2219

2320
private const string SHORT_JSON = @"{
2421
""key0"": null,
@@ -42,40 +39,37 @@ public void GlobalSetup()
4239

4340
var gqlRequest = new GraphQLRequest { Query = SchemaIntrospection.IntrospectionQuery };
4441
var gqlRequestJson = Serializer.ToJson(gqlRequest);
45-
_httpRequest = GetHttpRequestFor(gqlRequestJson);
42+
_httpRequestBody = GetHttpRequestBodyFor(gqlRequestJson);
4643

4744
gqlRequest.OperationName = "someOperationName";
48-
gqlRequest.Inputs = new GraphQLSerializer().Deserialize<Inputs>(SHORT_JSON);
45+
gqlRequest.Variables = new StjDeserializer().Deserialize<Inputs>(SHORT_JSON);
4946
var gqlRequestJson2 = Serializer.ToJson(gqlRequest);
50-
_httpRequest2 = GetHttpRequestFor(gqlRequestJson2);
47+
_httpRequestBody2 = GetHttpRequestBodyFor(gqlRequestJson2);
5148
}
5249

53-
private static HttpRequest GetHttpRequestFor(string gqlRequestJson)
50+
private static Stream GetHttpRequestBodyFor(string gqlRequestJson)
5451
{
55-
var httpContext = new DefaultHttpContext();
56-
httpContext.Features.Set<IRequestBodyPipeFeature>(new RequestBodyPipeFeature(httpContext));
57-
httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(gqlRequestJson));
58-
return httpContext.Request;
52+
return new MemoryStream(Encoding.UTF8.GetBytes(gqlRequestJson));
5953
}
6054

6155
[IterationSetup]
6256
public void IterationSetup()
6357
{
6458
// Reset stream positions
65-
_httpRequest.Body.Position = 0;
66-
_httpRequest2.Body.Position = 0;
59+
_httpRequestBody.Position = 0;
60+
_httpRequestBody2.Position = 0;
6761
}
6862

6963
[Benchmark(Baseline = true)]
70-
public Task<GraphQLRequestDeserializationResult> NewtonsoftJson() => _nsjDeserializer.DeserializeFromJsonBodyAsync(_httpRequest);
64+
public ValueTask<GraphQLRequest[]> NewtonsoftJson() => _nsjDeserializer.ReadAsync<GraphQLRequest[]>(_httpRequestBody);
7165

7266
[Benchmark]
73-
public Task<GraphQLRequestDeserializationResult> SystemTextJson() => _stjDeserializer.DeserializeFromJsonBodyAsync(_httpRequest);
67+
public ValueTask<GraphQLRequest[]> SystemTextJson() => _stjDeserializer.ReadAsync<GraphQLRequest[]>(_httpRequestBody);
7468

7569
[Benchmark]
76-
public Task<GraphQLRequestDeserializationResult> NewtonsoftJson_WithOpNameAndVariables() => _nsjDeserializer.DeserializeFromJsonBodyAsync(_httpRequest2);
70+
public ValueTask<GraphQLRequest[]> NewtonsoftJson_WithOpNameAndVariables() => _nsjDeserializer.ReadAsync<GraphQLRequest[]>(_httpRequestBody2);
7771

7872
[Benchmark]
79-
public Task<GraphQLRequestDeserializationResult> SystemTextJson_WithOpNameAndVariables() => _stjDeserializer.DeserializeFromJsonBodyAsync(_httpRequest2);
73+
public ValueTask<GraphQLRequest[]> SystemTextJson_WithOpNameAndVariables() => _stjDeserializer.ReadAsync<GraphQLRequest[]>(_httpRequestBody2);
8074
}
8175
}

src/Benchmarks/Benchmarks/DeserializeInputsFromJsonBenchmark.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BenchmarkDotNet.Attributes;
2-
using NsjDeserializer = GraphQL.Server.Transports.AspNetCore.NewtonsoftJson.GraphQLRequestDeserializer;
3-
using StjDeserializer = GraphQL.Server.Transports.AspNetCore.SystemTextJson.GraphQLRequestDeserializer;
2+
using NsjDeserializer = GraphQL.NewtonsoftJson.GraphQLSerializer;
3+
using StjDeserializer = GraphQL.SystemTextJson.GraphQLSerializer;
44

55
namespace GraphQL.Server.Benchmarks
66
{
@@ -37,9 +37,9 @@ public void GlobalSetup()
3737
// other custom implementations someone else might want to contribute.
3838

3939
[Benchmark(Baseline = true)]
40-
public Inputs NewtonsoftJson() => _nsjDeserializer.DeserializeInputsFromJson(SHORT_JSON);
40+
public Inputs NewtonsoftJson() => _nsjDeserializer.Deserialize<Inputs>(SHORT_JSON);
4141

4242
[Benchmark]
43-
public Inputs SystemTextJson() => _stjDeserializer.DeserializeInputsFromJson(SHORT_JSON);
43+
public Inputs SystemTextJson() => _stjDeserializer.Deserialize<Inputs>(SHORT_JSON);
4444
}
4545
}

0 commit comments

Comments
 (0)