Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async request stream deserialization with System.Text.Json #299

Merged
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
51f1a91
First sweep of async'ing stream deserialization
benmccallum Jan 6, 2020
d26142f
Custom property name as per Newtonsoft.Json (not working tho...)
benmccallum Jan 6, 2020
6fbb877
Fully async response body reading
benmccallum Jan 7, 2020
eca0e15
ConfigureAwait and update comment.
benmccallum Jan 7, 2020
3600b96
Another configure await
benmccallum Jan 7, 2020
513ccda
Fix for requests so camelCase was used for incoming JSON property names.
benmccallum Jan 7, 2020
018c29a
Revert encoding change. Wth
benmccallum Jan 8, 2020
f1fe909
Start separating out serialization implementations
benmccallum Jan 8, 2020
a2307a2
Remove netcoreapp3.0 from Core.csproj as not needed
benmccallum Jan 8, 2020
4af1a75
Remove configuration of IDocumentWriter as will soon have multiple fo…
benmccallum Jan 8, 2020
8e8da37
Only new up a default IGraphQLRequest in scenarios that need it.
benmccallum Jan 8, 2020
8c90074
Put back comment re: UserContext for state exchange
benmccallum Jan 8, 2020
93b99b1
GraphQLRequest as a real class that can be overridden.
benmccallum Jan 13, 2020
4f233a1
Use GraphQLRequest ctor.
benmccallum Jan 13, 2020
e57b728
Update middleware hookup extensions.
benmccallum Jan 13, 2020
de95d3a
Add todo for later.
benmccallum Jan 13, 2020
f8f6b4e
Merge branch 'develop' into feature/system.text.json-support
benmccallum Jan 14, 2020
ae4a395
Target versions, builds and nuget stuff
benmccallum Jan 15, 2020
c9b0d52
Merge branch 'feature/system.text.json-support' of https://github.com…
benmccallum Jan 15, 2020
073b580
Fix references
benmccallum Jan 15, 2020
4ecdfdc
target 3.1 for altair ui too
benmccallum Jan 15, 2020
879177a
Align package names with full namespaces
benmccallum Jan 15, 2020
75af9d8
Update src/Ui.Playground/Ui.Playground.csproj
benmccallum Jan 16, 2020
6afca6a
Update src/Transports.AspNetCore/Transports.AspNetCore.csproj
benmccallum Jan 16, 2020
e19f215
Move shared stuff into Core so Serializers take a dep on that
benmccallum Jan 16, 2020
1f2d6d7
IsNetCore30OnwardsTarget -> IsNetCore3OnwardsTarget
benmccallum Jan 16, 2020
286d425
Remove Microsoft.Extensions.DependencyInjection.Abstractions from Cor…
benmccallum Jan 16, 2020
2eeb05b
Move keys back inside here, like before.
benmccallum Jan 16, 2020
f163c62
Merge branch 'feature/system.text.json-support' of https://github.com…
benmccallum Jan 16, 2020
235437f
Fix mix of tabs and spaces
benmccallum Jan 16, 2020
227b4e3
Update readme
benmccallum Jan 16, 2020
e28cd72
Align and condense configuration
benmccallum Jan 16, 2020
12e4121
Fix tabbing in code of readme
benmccallum Jan 16, 2020
dddc757
Update README.md
benmccallum Jan 16, 2020
4bf7e8b
Update README.md
benmccallum Jan 16, 2020
c88874f
Remove this this too
benmccallum Jan 16, 2020
be7854e
Use ContentLength if given to optimize deserialization with ArrayPool
benmccallum Jan 16, 2020
d6035a9
Upgrade to latest graphql newtonsoft package
benmccallum Jan 16, 2020
5300d17
Fix websockets tests.
benmccallum Jan 16, 2020
cfa8096
Update tests/Transports.Subscriptions.WebSockets.Tests/WebSocketWrite…
benmccallum Jan 20, 2020
26bbaa3
fix: Queries with variables should be able to deserialize OK
benmccallum Jan 20, 2020
902e1c5
Merge branch 'feature/system.text.json-support' of https://github.com…
benmccallum Jan 20, 2020
3973267
More tests, no sync IO allowed in websockets either
benmccallum Jan 20, 2020
2ee3cec
Avoid an allocation by using `TryGetBuffer`
benmccallum Jan 21, 2020
7dedb08
Working through feedback
benmccallum Jan 21, 2020
7d2814a
Thank you, David Fowler!
benmccallum Jan 21, 2020
17fc7ff
Rename tests and add complex variable
benmccallum Jan 21, 2020
b0860b9
Fixes
benmccallum Jan 21, 2020
b6ace2b
Flip dependencies around
benmccallum Jan 22, 2020
370704c
Put back AllowSyncIO until core project isn't writing syncly
benmccallum Jan 22, 2020
b1996ba
WIP tests
benmccallum Jan 22, 2020
582f7e6
Update src/Transports.AspNetCore.NewtonsoftJson/Transports.AspNetCore…
benmccallum Jan 22, 2020
3ce4ee4
Update src/Transports.AspNetCore.SystemTextJson/Transports.AspNetCore…
benmccallum Jan 22, 2020
055f638
Move inputs handling behind interface too
benmccallum Jan 22, 2020
6f1e393
Merge branch 'feature/system.text.json-support' of https://github.com…
benmccallum Jan 22, 2020
994bce1
Fix non-existant property usage
benmccallum Jan 22, 2020
d1eaa52
Should deserialize into JsonElement
benmccallum Jan 22, 2020
02e95f1
Prepare for downstream changes
benmccallum Feb 3, 2020
c074f18
Get ready for GraphQL.SystemTextJson
benmccallum Feb 3, 2020
8f2929b
Ugh, so painful. All tests passing.
benmccallum Feb 3, 2020
db65fad
Get rid of some more Newtonsoft.Json reliance.
benmccallum Feb 6, 2020
e039a45
Remove this too as it can be transitive.
benmccallum Feb 6, 2020
5650acd
Update readme.
benmccallum Feb 6, 2020
853e8c7
Back to NuGet deps.
benmccallum Feb 6, 2020
475834b
Fix serialization of GraphQLRequest and tests
benmccallum Feb 6, 2020
98a17d6
Build new projects with latest paths.
benmccallum Feb 6, 2020
0745a32
Remove unnecessary pkg ref
benmccallum Feb 6, 2020
278b18d
Comment this method.
benmccallum Feb 6, 2020
d666343
Re-order this msg.
benmccallum Feb 6, 2020
b87c20b
Add a note for this guy.
benmccallum Feb 6, 2020
7ddc2da
Refactor the serialization a bit to another class.
benmccallum Feb 6, 2020
44aab98
Fix compilation ifs.
benmccallum Feb 6, 2020
a4211d7
Fix grammar.
benmccallum Feb 6, 2020
b4cfc02
Add link in exception to docs.
benmccallum Feb 6, 2020
a9bf6b9
Spelling.
benmccallum Feb 6, 2020
0e37e0b
Bump dotnet SDK version.
benmccallum Feb 6, 2020
9663ab5
Document IGraphQLRequestDeserializer.
benmccallum Feb 10, 2020
5ec4dc5
Simplify and document ShouldBe extensions.
benmccallum Feb 10, 2020
ef53078
Internalize serializer and its methods.
benmccallum Feb 10, 2020
5535113
Consistent handling of UI models and using statements.
benmccallum Feb 10, 2020
973cf4b
Add missing GraphiQL tags meta.
benmccallum Feb 10, 2020
8ad499a
Add package tags to newer serializer projects.
benmccallum Feb 10, 2020
30591ed
Document middleware some more. Rename bool property.
benmccallum Feb 10, 2020
6e24513
Handle null configure actions passed to deserializers.
benmccallum Feb 10, 2020
9753f44
Add GraphQLBuilder convenience ext methods for Startup.
benmccallum Feb 10, 2020
8268a40
Update readme to match latest Startup.cs
benmccallum Feb 10, 2020
b1d0089
Tweak readme again.
benmccallum Feb 10, 2020
17629d9
Cancellation support.
benmccallum Feb 10, 2020
4f3f0b8
Remove ConfigureAwait(false) from dotnet core proj.
benmccallum Feb 10, 2020
cf8b4d1
Move cancellationToken get up.
benmccallum Feb 10, 2020
73bc048
More async cancellation stuff
benmccallum Feb 10, 2020
f6ea7ed
Use cancellation token with IDocumentWriter.
benmccallum Feb 10, 2020
766c136
Refactor extension methods to be more unified.
benmccallum Feb 10, 2020
97fb779
Fix param ref in xml comment.
benmccallum Feb 10, 2020
0be8b3c
Helper method for cancellation.
benmccallum Feb 10, 2020
7e7a551
Bump GraphQL for new DocWriter ctors.
benmccallum Feb 10, 2020
561cf8f
Format csproj. Remove whitespace,
benmccallum Feb 11, 2020
8ba80d1
Solution folder for serialization.
benmccallum Feb 11, 2020
ebb1c72
Use ThrowIfCancellationRequested directly.
benmccallum Feb 11, 2020
d5ba438
Use cancellationToken in NewtonsoftJson.GraphQLRequestDeserializer.
benmccallum Feb 13, 2020
bf0628b
WIP refactor.
benmccallum Feb 13, 2020
2114859
Fiddling with tests.
benmccallum Feb 13, 2020
a59a766
Fun times.
benmccallum Feb 13, 2020
1942b64
Fixing tests.
benmccallum Feb 13, 2020
5bc8b32
Fixing more tests.
benmccallum Feb 13, 2020
f568069
All tests passing again. And form POST ones.
benmccallum Feb 13, 2020
17d10c5
Refactor.
benmccallum Feb 13, 2020
4889711
Fix comment.
benmccallum Feb 13, 2020
54c386c
Final test.
benmccallum Feb 13, 2020
b13ffa7
Ugh.
benmccallum Feb 13, 2020
0428b77
Seal internal gql request classes.
benmccallum Feb 17, 2020
2862f91
Simplify DeserializeFromXyz methods.
benmccallum Feb 17, 2020
f82101b
Simplify query and form deserialization back to middleware.
benmccallum Feb 17, 2020
3f375be
Check cancellation after readasync.
benmccallum Feb 17, 2020
5819ad2
Refactor.
benmccallum Feb 17, 2020
a29be31
Pass HttpResponse not full ctx.
benmccallum Feb 17, 2020
8037840
Revert back content types error to include Form.
benmccallum Feb 17, 2020
1c068ad
Capitalized const var name.
benmccallum Feb 17, 2020
93c1dd9
Newlines between break;
benmccallum Feb 17, 2020
6a23716
Support querystring args in all request types.
benmccallum Feb 17, 2020
72f1735
Fix comment
benmccallum Feb 17, 2020
e5ae897
Fix up batch middleware extension point and make var name clearer.
benmccallum Feb 17, 2020
9cfdd1c
More tests for error responses.
benmccallum Feb 17, 2020
8d446cc
Revert sln file re-ordered projs.
benmccallum Feb 17, 2020
58665b2
Update readme.
benmccallum Feb 17, 2020
46cc517
More reverting of the accidental sln file changes.
benmccallum Feb 17, 2020
a2d2b70
Remove unnecessary cast.
benmccallum Feb 17, 2020
4c93871
Inline test data.
benmccallum Feb 17, 2020
5fd3b9d
Additional application/graphql test cases.
benmccallum Feb 17, 2020
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
31 changes: 19 additions & 12 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,45 @@
</PropertyGroup>

<PropertyGroup>
<IsNetCore30OnwardsTarget>$(TargetFramework.Equals('netcoreapp3.0'))</IsNetCore30OnwardsTarget>
<IsNetCore3OnwardsTarget>$(TargetFramework.StartsWith('netcoreapp3.'))</IsNetCore3OnwardsTarget>
</PropertyGroup>

<PropertyGroup Label="Net Core 3.0" Condition="'$(IsNetCore30OnwardsTarget)' == 'True'">
<PropertyGroup Label="Net Core 3.1" Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<MicrosoftAspNetCoreTestHostVersion>3.1.0</MicrosoftAspNetCoreTestHostVersion>
<MicrosoftExtensionsLoggingVersion>3.1.0</MicrosoftExtensionsLoggingVersion>
<MicrosoftExtensionsOptionsVersion>3.1.0</MicrosoftExtensionsOptionsVersion>
<MicrosoftExtensionsDependencyInjectionVersion>3.1.0</MicrosoftExtensionsDependencyInjectionVersion>
<MicrosoftExtensionsDependencyInjectionAbstractionsVersion>3.1.0</MicrosoftExtensionsDependencyInjectionAbstractionsVersion>
</PropertyGroup>

<PropertyGroup Label="Net Core 3.0" Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<MicrosoftAspNetCoreTestHostVersion>3.0.0</MicrosoftAspNetCoreTestHostVersion>
<MicrosoftExtensionsLoggingVersion>3.0.0</MicrosoftExtensionsLoggingVersion>
<MicrosoftExtensionsOptionsVersion>3.0.0</MicrosoftExtensionsOptionsVersion>
<MicrosoftExtensionsDependencyInjectionVersion>3.0.0</MicrosoftExtensionsDependencyInjectionVersion>
<MicrosoftExtensionsDependencyInjectionAbstractionsVersion>3.0.0</MicrosoftExtensionsDependencyInjectionAbstractionsVersion>
</PropertyGroup>

<PropertyGroup Label="Net Core 2.2" Condition="'$(IsNetCore30OnwardsTarget)' == 'False'">
<PropertyGroup Label="Net Core 2.2" Condition="'$(IsNetCore3OnwardsTarget)' == 'False'">
<MicrosoftAspNetCoreVersion>2.2.0</MicrosoftAspNetCoreVersion>
<MicrosoftAspNetCoreAuthorizationVersion>2.2.0</MicrosoftAspNetCoreAuthorizationVersion>
<MicrosoftAspNetCoreHostingAbstractionsVersion>2.2.0</MicrosoftAspNetCoreHostingAbstractionsVersion>
<MicrosoftAspNetCoreHttpAbstractionsVersion>2.2.0</MicrosoftAspNetCoreHttpAbstractionsVersion>
<MicrosoftAspNetCoreHttpVersion>2.2.2</MicrosoftAspNetCoreHttpVersion>
<MicrosoftAspNetCoreTestHostVersion>2.2.0</MicrosoftAspNetCoreTestHostVersion>
<MicrosoftAspNetCoreWebSocketsVersion>2.2.1</MicrosoftAspNetCoreWebSocketsVersion>
<MicrosoftExtensionsLoggingVersion>2.2.0</MicrosoftExtensionsLoggingVersion>
<MicrosoftExtensionsOptionsVersion>2.2.0</MicrosoftExtensionsOptionsVersion>
<MicrosoftExtensionsDependencyInjectionVersion>2.2.0</MicrosoftExtensionsDependencyInjectionVersion>
<MicrosoftExtensionsDependencyInjectionAbstractionsVersion>2.2.0</MicrosoftExtensionsDependencyInjectionAbstractionsVersion>
</PropertyGroup>

<PropertyGroup Label="Package dependency versions">
<MicrosoftAspNetCoreVersion>2.2.0</MicrosoftAspNetCoreVersion>
<MicrosoftAspNetCoreHttpAbstractionsVersion>2.2.0</MicrosoftAspNetCoreHttpAbstractionsVersion>
<MicrosoftAspNetCoreHttpVersion>2.2.2</MicrosoftAspNetCoreHttpVersion>
<MicrosoftAspNetCoreWebSocketsVersion>2.2.1</MicrosoftAspNetCoreWebSocketsVersion>
<MicrosoftAspNetCoreAuthorizationVersion>2.2.0</MicrosoftAspNetCoreAuthorizationVersion>
<MicrosoftAspNetCoreHostingAbstractionsVersion>2.2.0</MicrosoftAspNetCoreHostingAbstractionsVersion>

<MicrosoftNETTestSdkVersion>16.3.0</MicrosoftNETTestSdkVersion>
<CastleCoreVersion>4.4.0</CastleCoreVersion>
<NSubstituteVersion>3.1.0</NSubstituteVersion>
<NewtonsoftJsonVersion>12.0.2</NewtonsoftJsonVersion>
<GraphQLVersion>3.0.0-preview-1430</GraphQLVersion>
<NewtonsoftJsonVersion>12.0.3</NewtonsoftJsonVersion>
<GraphQLVersion>3.0.0-preview-1470</GraphQLVersion>
<MoqVersion>4.13.1</MoqVersion>
<ShouldlyVersion>3.0.2</ShouldlyVersion>

Expand Down
12 changes: 12 additions & 0 deletions GraphQL.Server.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{5C07
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ui.Altair", "src\Ui.Altair\Ui.Altair.csproj", "{008CFAAB-64B6-4948-99FA-E8735CA7E81A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transports.AspNetCore.NewtonsoftJson", "src\Transports.AspNetCore.NewtonsoftJson\Transports.AspNetCore.NewtonsoftJson.csproj", "{24975BA5-46B0-4E3A-8703-9599483138B8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transports.AspNetCore.SystemTextJson", "src\Transports.AspNetCore.SystemTextJson\Transports.AspNetCore.SystemTextJson.csproj", "{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -121,6 +125,14 @@ Global
{008CFAAB-64B6-4948-99FA-E8735CA7E81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{008CFAAB-64B6-4948-99FA-E8735CA7E81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{008CFAAB-64B6-4948-99FA-E8735CA7E81A}.Release|Any CPU.Build.0 = Release|Any CPU
{24975BA5-46B0-4E3A-8703-9599483138B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24975BA5-46B0-4E3A-8703-9599483138B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24975BA5-46B0-4E3A-8703-9599483138B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24975BA5-46B0-4E3A-8703-9599483138B8}.Release|Any CPU.Build.0 = Release|Any CPU
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CEB56EE-C58D-4EF8-90E3-5B53D9354C47}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
GraphQL for .NET - Subscription Transport WebSockets
====================================================

>WARNING: not tested in heavy production use! That said if you are using this in production
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
>drop me a line to tell me how's it working for you. Maybe I can take this disclaimer off.

[![Build status](https://ci.appveyor.com/api/projects/status/x0nf67vfao60wf7e/branch/master?svg=true)](https://ci.appveyor.com/project/graphql-dotnet-ci/server/branch/master)

Provides the following packages:
Expand All @@ -12,11 +9,13 @@ Provides the following packages:
|---------|-----------|
| GraphQL.Server.Core | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Core)](https://www.nuget.org/packages/GraphQL.Server.Core/) |
| GraphQL.Server.Transports.AspNetCore | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.AspNetCore)](https://www.nuget.org/packages/GraphQL.Server.Transports.AspNetCore/) |
| 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/) |
| 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/) |
| 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/) |
| GraphQL.Server.Transports.WebSockets | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Transports.WebSockets)](https://www.nuget.org/packages/GraphQL.Server.Transports.WebSockets/) |
| GraphQL.Server.Ui.Altair | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Ui.Altair)](https://www.nuget.org/packages/GraphQL.Server.Ui.Altair/) |
| GraphQL.Server.Ui.Playground | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Ui.Playground)](https://www.nuget.org/packages/GraphQL.Server.Ui.Playground/) |
| GraphQL.Server.Ui.GraphiQL | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Ui.GraphiQL)](https://www.nuget.org/packages/GraphQL.Server.Ui.GraphiQL/) |
| GraphQL.Server.Ui.Altair | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Ui.Altair)](https://www.nuget.org/packages/GraphQL.Server.Ui.Altair/) |
| GraphQL.Server.Ui.Voyager | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Ui.Voyager)](https://www.nuget.org/packages/GraphQL.Server.Ui.Voyager/) |
| GraphQL.Server.Authorization.AspNetCore | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Server.Authorization.AspNetCore)](https://www.nuget.org/packages/GraphQL.Server.Authorization.AspNetCore/) |

Expand All @@ -27,34 +26,48 @@ Transport compatible with [Apollo](https://github.com/apollographql/subscription
For just the HTTP middleware:
>`dotnet add package GraphQL.Server.Transports.AspNetCore`

The HTTP middleware needs an `IGraphQLRequestDeserializer` implementation:
benmccallum marked this conversation as resolved.
Show resolved Hide resolved
> .NET Core 3+:
> `dotnet add package GraphQL.Server.Serialization.SystemTextJson`
> Legacy (prior to .NET Core 3):
> `dotnet add package GraphQL.Server.Serialization.NewtonsoftJson`
> (or your own)

For the WebSocket subscription protocol (depends on above) middleware:
>`dotnet add package GraphQL.Server.Transports.WebSockets`

For the UI middleware/s:
>`dotnet add package GraphQL.Server.Ui.Altair`
>`dotnet add package GraphQL.Server.Ui.GraphiQL`
>`dotnet add package GraphQL.Server.Ui.Playground`
>`dotnet add package GraphQL.Server.Ui.Altair`
>`dotnet add package GraphQL.Server.Ui.Voyager`


### Configure

See the sample project's Startup.cs for full details.

``` csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ChatSchema>();

// Add GraphQL services and configure options
services.AddGraphQL(options =>
{
options.EnableMetrics = true;
options.ExposeExceptions = this.Environment.IsDevelopment();
})
.AddWebSockets() // Add required services for web socket support
.AddDataLoader(); // Add required services for DataLoader support
services
.AddSingleton<IChat, Chat>()
.AddSingleton<ChatSchema>()
.AddGraphQL(options =>
{
options.EnableMetrics = Environment.IsDevelopment();
options.ExposeExceptions = Environment.IsDevelopment();
options.UnhandledExceptionDelegate = ctx => { Console.WriteLine(ctx.OriginalException) };
})
// Add required services for de/serialization
.AddSystemTextJson(deserializerSettings => { }, serializerSettings => { }) // For .NET Core 3+
.AddNewtonsoftJson(deserializerSettings => { }, serializerSettings => { }) // For everything else
.AddWebSockets() // Add required services for web socket support
.AddDataLoader() // Add required services for DataLoader support
.AddGraphTypes(typeof(ChatSchema)) // Add all IGraphType implementors in assembly which ChatSchema exists
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
// this is required for websockets support
app.UseWebSockets();
Expand Down Expand Up @@ -91,10 +104,11 @@ access the properties including your actual `UserContext` by using the

## Sample

Samples.Server shows a simple Chat style example of how subscription transport is used
with GraphiQL integration. An example works for `netcoreapp2.2` and `netcoreapp3.0` platforms.
Samples.Server shows a simple Chat example demonstrating the subscription transport.
It can be run as `netcoreapp2.2`, `netcoreapp3.0` or `netcoreapp3.1`, and supports
various GraphQL client IDEs (by default opening GraphQL Playground).

Here are example queries to get started. Use three browser tabs or better yet windows
Here are some example queries to get started. Use three browser tabs or better yet windows
to view the changes.

### Subscription 1
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test: off
skip_branch_with_pr: false

install:
- ps: choco install dotnetcore-sdk --no-progress --confirm --version 3.0.100
- ps: choco install dotnetcore-sdk --no-progress --confirm --version 3.1.101
- dotnet --version

on_failure:
Expand Down
7 changes: 4 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ var configuration = Argument<string>("configuration", "Release");
var artifactsDir = Directory(Argument<string>("artifactsDir", "./artifacts"));
var publishDir = Directory(Argument<string>("publishDir", "./publish"));
var runtime = Argument<string>("runtime", "win-x64");
var sln = "./GraphQL.Server.Transports.sln";
var projectFiles = new [] {
"./src/Core/Core.csproj",
"./src/Transports.AspNetCore/Transports.AspNetCore.csproj",
"./src/Transports.AspNetCore.NewtonsoftJson/Transports.AspNetCore.NewtonsoftJson.csproj",
"./src/Transports.AspNetCore.SystemTextJson/Transports.AspNetCore.SystemTextJson.csproj",
"./src/Transports.Subscriptions.Abstractions/Transports.Subscriptions.Abstractions.csproj",
"./src/Transports.Subscriptions.WebSockets/Transports.Subscriptions.WebSockets.csproj",
"./src/Ui.Playground/Ui.Playground.csproj",
Expand Down Expand Up @@ -113,8 +114,8 @@ Task("SetVersion")
Task("Test")
.Does(()=>
{
var projectFiles = GetFiles("./tests/**/*.csproj");
foreach (var file in projectFiles)
var testProjectFiles = GetFiles("./tests/**/*.csproj");
foreach (var file in testProjectFiles)
{
DotNetCoreTest(file.FullPath);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/Samples.Schemas.Chat/Samples.Schemas.Chat.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
Expand All @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="$(GraphQLVersion)" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="$(GraphQLVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Transports.Subscriptions.Abstractions\Transports.Subscriptions.Abstractions.csproj" />
Expand Down
12 changes: 8 additions & 4 deletions samples/Samples.Server/GraphQLHttpMiddlewareWithLogs.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using GraphQL.Server.Transports.AspNetCore;
using GraphQL.Server.Common;
using GraphQL.Server.Transports.AspNetCore;
using GraphQL.Server.Transports.AspNetCore.Common;
using GraphQL.Types;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -16,8 +16,12 @@ public class GraphQLHttpMiddlewareWithLogs<TSchema> : GraphQLHttpMiddleware<TSch
{
private readonly ILogger _logger;

public GraphQLHttpMiddlewareWithLogs(ILogger<GraphQLHttpMiddleware<TSchema>> logger, RequestDelegate next, PathString path, Action<JsonSerializerSettings> configure)
: base(next, path, configure)
public GraphQLHttpMiddlewareWithLogs(
ILogger<GraphQLHttpMiddleware<TSchema>> logger,
RequestDelegate next,
PathString path,
IGraphQLRequestDeserializer requestDeserializer)
: base(next, path, requestDeserializer)
{
_logger = logger;
}
Expand Down
14 changes: 9 additions & 5 deletions samples/Samples.Server/Samples.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
<AssemblyName>GraphQL.Samples.Server</AssemblyName>
<RootNamespace>GraphQL.Samples.Server</RootNamespace>
</PropertyGroup>
Expand All @@ -11,14 +11,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="$(GraphQLVersion)" />

benmccallum marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Serilog" Version="$(SerilogVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(SerilogAspNetCoreVersion)" />
<PackageReference Include="Serilog.Sinks.Console" Version="$(SerilogSinksConsoleVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Transports.AspNetCore\Transports.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\Transports.Subscriptions.WebSockets\Transports.Subscriptions.WebSockets.csproj" />
<ProjectReference Include="..\..\src\Ui.GraphiQL\Ui.GraphiQL.csproj" />
<ProjectReference Include="..\..\src\Ui.Playground\Ui.Playground.csproj" />
Expand All @@ -27,9 +26,14 @@
<ProjectReference Include="..\Samples.Schemas.Chat\Samples.Schemas.Chat.csproj" />
</ItemGroup>

<ItemGroup Label="References for .NET Core 2.2" Condition="'$(IsNetCore30OnwardsTarget)' == 'False'">
<ItemGroup Label="References for .NET Core 3.0+" Condition="'$(IsNetCore3OnwardsTarget)' == 'True'">
<ProjectReference Include="..\..\src\Transports.AspNetCore.SystemTextJson\Transports.AspNetCore.SystemTextJson.csproj" />
</ItemGroup>

<ItemGroup Label="References for .NET Core 2.2" Condition="'$(IsNetCore3OnwardsTarget)' == 'False'">
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="$(MicrosoftAspNetCoreWebSocketsVersion)" />
<ProjectReference Include="..\..\src\Transports.AspNetCore.NewtonsoftJson\Transports.AspNetCore.NewtonsoftJson.csproj" />
</ItemGroup>

</Project>
22 changes: 6 additions & 16 deletions samples/Samples.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Collections.Generic;

#if !NETCOREAPP2_2
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Hosting;
#endif

Expand Down Expand Up @@ -41,32 +40,23 @@ public Startup(IConfiguration configuration, IWebHostEnvironment environment)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
#if NETCOREAPP3_0
// Workaround until GraphQL can swap off Newtonsoft.Json and onto the new MS one.
// Depending on whether you're using IIS or Kestrel, the code required is different
// See: https://github.com/graphql-dotnet/graphql-dotnet/issues/1116
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
#endif

services
.AddSingleton<IChat, Chat>()
.AddSingleton<ChatSchema>()
.AddGraphQL(options =>
{
options.EnableMetrics = true;
options.EnableMetrics = Environment.IsDevelopment();
options.ExposeExceptions = Environment.IsDevelopment();
options.UnhandledExceptionDelegate = ctx =>
{
Console.WriteLine("error: " + ctx.OriginalException.Message);
};
})
#if NETCOREAPP2_2
.AddNewtonsoftJson(deserializerSettings => { }, serializerSettings => { })
#else
.AddSystemTextJson(deserializerSettings => { }, serializerSettings => { })
#endif
.AddWebSockets()
.AddDataLoader()
.AddGraphTypes(typeof(ChatSchema));
Expand Down
Loading