From d0cc3adfede1789e51a5a5713807f01d87d5f495 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sun, 27 Feb 2022 21:58:44 +0300 Subject: [PATCH 1/2] ne5 --- README.md | 6 +++--- src/AspNetCore/Example/Example.csproj | 6 +++--- src/AspNetCore/Example/Startup.cs | 3 --- src/AspNetCoreCustom/Example/Example.csproj | 4 ++-- src/AspNetCoreCustom/Example/GraphQLMiddleware.cs | 14 +++++++++----- src/AspNetCoreMulti/Example/Example.csproj | 6 +++--- src/AspNetCoreMulti/Example/Startup.cs | 4 ++-- src/StarWars/InputValidationRule.cs | 4 +--- src/StarWars/StarWars.csproj | 2 +- src/StarWars/StarWarsData.cs | 9 +++++---- src/StarWars/StarWarsSchema.cs | 8 +++++--- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 4266f40..79bbfd8 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Examples for [GraphQL.NET](https://github.com/graphql-dotnet/graphql-dotnet). | Project | Description | |------------------|-------------| -| AspNetCore | ASP.NET Core 3.1 app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project | -| AspNetCoreMulti | ASP.NET Core 3.1 multi-tenant (two schemas) app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project | -| AspNetCoreCustom | ASP.NET Core 3.1 app with custom GraphQL and UI middlewares | +| AspNetCore | ASP.NET Core 5 app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project | +| AspNetCoreMulti | ASP.NET Core 5 multi-tenant (two schemas) app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project | +| AspNetCoreCustom | ASP.NET Core 5 app with custom GraphQL and UI middlewares | | AspNetWebApi | .NET Framework 4.6.1 Web API example | | AzureFunctions | Using GraphQL in Azure Functions | | StarWars | StarWars demo schema used in all examples | diff --git a/src/AspNetCore/Example/Example.csproj b/src/AspNetCore/Example/Example.csproj index ec69666..8cb253d 100644 --- a/src/AspNetCore/Example/Example.csproj +++ b/src/AspNetCore/Example/Example.csproj @@ -1,14 +1,14 @@ - netcoreapp3.1 + net5 true latest - - + + diff --git a/src/AspNetCore/Example/Startup.cs b/src/AspNetCore/Example/Startup.cs index 236374d..a1c5c62 100644 --- a/src/AspNetCore/Example/Startup.cs +++ b/src/AspNetCore/Example/Startup.cs @@ -41,10 +41,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); - // add http for Schema at default url /graphql app.UseGraphQL(); - - // use graphql-playground at default url /ui/playground app.UseGraphQLPlayground(); } } diff --git a/src/AspNetCoreCustom/Example/Example.csproj b/src/AspNetCoreCustom/Example/Example.csproj index 9de4bfa..59e50c2 100644 --- a/src/AspNetCoreCustom/Example/Example.csproj +++ b/src/AspNetCoreCustom/Example/Example.csproj @@ -1,13 +1,13 @@ - netcoreapp3.1 + net5 true latest - + diff --git a/src/AspNetCoreCustom/Example/GraphQLMiddleware.cs b/src/AspNetCoreCustom/Example/GraphQLMiddleware.cs index 36c65a9..79ce331 100644 --- a/src/AspNetCoreCustom/Example/GraphQLMiddleware.cs +++ b/src/AspNetCoreCustom/Example/GraphQLMiddleware.cs @@ -54,6 +54,8 @@ private async Task ExecuteAsync(HttpContext context, ISchema schema) { var request = Deserialize(context.Request.Body); + var start = DateTime.UtcNow; + var result = await _executer.ExecuteAsync(_ => { _.Schema = schema; @@ -61,14 +63,16 @@ private async Task ExecuteAsync(HttpContext context, ISchema schema) _.OperationName = request?.OperationName; _.Inputs = request?.Variables.ToInputs(); _.UserContext = _settings.BuildUserContext?.Invoke(context); - _.ValidationRules = DocumentValidator.CoreRules.Concat(new [] { new InputValidationRule() }); + _.ValidationRules = DocumentValidator.CoreRules.Concat(new[] { new InputValidationRule() }); _.EnableMetrics = _settings.EnableMetrics; - if (_settings.EnableMetrics) - { - _.FieldMiddleware.Use(); - } }); + + if (_settings.EnableMetrics) + { + result.EnrichWithApolloTracing(start); + } + await WriteResponseAsync(context, result); } diff --git a/src/AspNetCoreMulti/Example/Example.csproj b/src/AspNetCoreMulti/Example/Example.csproj index fc612b1..a1c5a6e 100644 --- a/src/AspNetCoreMulti/Example/Example.csproj +++ b/src/AspNetCoreMulti/Example/Example.csproj @@ -1,14 +1,14 @@ - netcoreapp3.1 + net5 true latest - - + + diff --git a/src/AspNetCoreMulti/Example/Startup.cs b/src/AspNetCoreMulti/Example/Startup.cs index bad1c28..93acf07 100644 --- a/src/AspNetCoreMulti/Example/Startup.cs +++ b/src/AspNetCoreMulti/Example/Startup.cs @@ -37,8 +37,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseGraphQL("/api/dogs"); app.UseGraphQL("/api/cats"); - app.UseGraphQLPlayground(new GraphQLPlaygroundOptions { GraphQLEndPoint = "/api/dogs", Path = "/ui/dogs" }); - app.UseGraphQLPlayground(new GraphQLPlaygroundOptions { GraphQLEndPoint = "/api/cats", Path = "/ui/cats" }); + app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/dogs", Path = "/ui/dogs" }); + app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/cats", Path = "/ui/cats" }); } } } diff --git a/src/StarWars/InputValidationRule.cs b/src/StarWars/InputValidationRule.cs index 6e52425..d5cdcfd 100644 --- a/src/StarWars/InputValidationRule.cs +++ b/src/StarWars/InputValidationRule.cs @@ -7,9 +7,7 @@ public class InputValidationRule : IValidationRule { public Task ValidateAsync(ValidationContext context) { - return Task.FromResult((INodeVisitor)new EnterLeaveListener(_ => - { - })); + return Task.FromResult((INodeVisitor)new NodeVisitors()); } } } diff --git a/src/StarWars/StarWars.csproj b/src/StarWars/StarWars.csproj index d1aabc7..dd190d2 100644 --- a/src/StarWars/StarWars.csproj +++ b/src/StarWars/StarWars.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/StarWars/StarWarsData.cs b/src/StarWars/StarWarsData.cs index 5d67e72..19939bb 100644 --- a/src/StarWars/StarWarsData.cs +++ b/src/StarWars/StarWarsData.cs @@ -1,9 +1,8 @@ +using StarWars.Types; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using GraphQL; -using StarWars.Types; namespace StarWars { @@ -58,8 +57,10 @@ public IEnumerable GetFriends(StarWarsCharacter character) var lookup = character.Friends; if (lookup != null) { - _humans.Where(h => lookup.Contains(h.Id)).Apply(friends.Add); - _droids.Where(d => lookup.Contains(d.Id)).Apply(friends.Add); + foreach (var h in _humans.Where(h => lookup.Contains(h.Id))) + friends.Add(h); + foreach (var d in _droids.Where(d => lookup.Contains(d.Id))) + friends.Add(d); } return friends; } diff --git a/src/StarWars/StarWarsSchema.cs b/src/StarWars/StarWarsSchema.cs index 6009862..2c02a47 100644 --- a/src/StarWars/StarWarsSchema.cs +++ b/src/StarWars/StarWarsSchema.cs @@ -1,5 +1,5 @@ +using GraphQL.Instrumentation; using GraphQL.Types; -using GraphQL.Utilities; using System; namespace StarWars @@ -9,8 +9,10 @@ public class StarWarsSchema : Schema public StarWarsSchema(IServiceProvider provider) : base(provider) { - Query = provider.GetRequiredService(); - Mutation = provider.GetRequiredService(); + Query = (StarWarsQuery)provider.GetService(typeof(StarWarsQuery)) ?? throw new InvalidOperationException(); + Mutation = (StarWarsMutation)provider.GetService(typeof(StarWarsMutation)) ?? throw new InvalidOperationException(); + + FieldMiddleware.Use(new InstrumentFieldsMiddleware()); } } } From ebc8c0160c72a659f0a50cf0e07b2dd61d848e7c Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sun, 27 Feb 2022 22:34:23 +0300 Subject: [PATCH 2/2] net5 TFM --- README.md | 2 +- src/AspNetCore/Example/Startup.cs | 14 +- src/AspNetCoreCustom/Example/Example.csproj | 2 +- src/AspNetCoreMulti/Example/Example.csproj | 4 +- src/AspNetCoreMulti/Example/Startup.cs | 18 +- .../WebApi/Controllers/GraphQLController.cs | 1 - src/AspNetWebApi/WebApi/Web.config | 584 +++++++++--------- src/AspNetWebApi/WebApi/WebApi.csproj | 35 +- src/AspNetWebApi/WebApi/packages.config | 16 +- src/AzureFunctions/Example/Example.csproj | 8 +- .../Example/GraphQLExecuterExtensions.cs | 2 +- src/AzureFunctions/Example/StarWars.cs | 2 +- src/AzureFunctions/Example/Startup.cs | 1 - 13 files changed, 353 insertions(+), 336 deletions(-) diff --git a/README.md b/README.md index 2f8603a..0bbc35a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Examples for [GraphQL.NET](https://github.com/graphql-dotnet/graphql-dotnet). | AspNetCore | ASP.NET Core 5 app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project | | AspNetCoreMulti | ASP.NET Core 5 multi-tenant (two schemas) app with GraphQL and Playground middlewares from [server](https://github.com/graphql-dotnet/server) project | | AspNetCoreCustom | ASP.NET Core 5 app with custom GraphQL and UI middlewares | -| AspNetWebApi | .NET Framework 4.6.1 Web API example | +| AspNetWebApi | .NET Framework 4.8 Web API example | | AzureFunctions | Using GraphQL in Azure Functions | | StarWars | StarWars demo schema used in all examples | | ClientNet462 | Example GraphQL client written in .NET 4.6.2 using Newtonsoft.Json 4.0.1 | diff --git a/src/AspNetCore/Example/Startup.cs b/src/AspNetCore/Example/Startup.cs index a1c5c62..a101f38 100644 --- a/src/AspNetCore/Example/Startup.cs +++ b/src/AspNetCore/Example/Startup.cs @@ -27,13 +27,13 @@ public void ConfigureServices(IServiceCollection services) services.AddLogging(builder => builder.AddConsole()); services.AddHttpContextAccessor(); - services.AddGraphQL(options => - { - options.EnableMetrics = true; - }) - .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true) - .AddSystemTextJson() - .AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User }); +#pragma warning disable CS0612 // Type or member is obsolete + services + .AddGraphQL(options => options.EnableMetrics = true) + .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true) + .AddSystemTextJson() + .AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User }); +#pragma warning restore CS0612 // Type or member is obsolete } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/src/AspNetCoreCustom/Example/Example.csproj b/src/AspNetCoreCustom/Example/Example.csproj index 59e50c2..47fbca4 100644 --- a/src/AspNetCoreCustom/Example/Example.csproj +++ b/src/AspNetCoreCustom/Example/Example.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AspNetCoreMulti/Example/Example.csproj b/src/AspNetCoreMulti/Example/Example.csproj index a1c5a6e..8642976 100644 --- a/src/AspNetCoreMulti/Example/Example.csproj +++ b/src/AspNetCoreMulti/Example/Example.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/AspNetCoreMulti/Example/Startup.cs b/src/AspNetCoreMulti/Example/Startup.cs index 93acf07..0b0841d 100644 --- a/src/AspNetCoreMulti/Example/Startup.cs +++ b/src/AspNetCoreMulti/Example/Startup.cs @@ -20,13 +20,13 @@ public void ConfigureServices(IServiceCollection services) services.AddLogging(builder => builder.AddConsole()); services.AddHttpContextAccessor(); - services.AddGraphQL(options => - { - options.EnableMetrics = true; - }) - .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true) - .AddSystemTextJson() - .AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User }); +#pragma warning disable CS0612 // Type or member is obsolete + services + .AddGraphQL(options => options.EnableMetrics = true) + .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true) + .AddSystemTextJson() + .AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User }); +#pragma warning restore CS0612 // Type or member is obsolete } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -37,8 +37,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseGraphQL("/api/dogs"); app.UseGraphQL("/api/cats"); - app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/dogs", Path = "/ui/dogs" }); - app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/cats", Path = "/ui/cats" }); + app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/dogs" }, "/ui/dogs"); + app.UseGraphQLPlayground(new PlaygroundOptions { GraphQLEndPoint = "/api/cats" }, "/ui/cats"); } } } diff --git a/src/AspNetWebApi/WebApi/Controllers/GraphQLController.cs b/src/AspNetWebApi/WebApi/Controllers/GraphQLController.cs index 521619d..bdaf747 100644 --- a/src/AspNetWebApi/WebApi/Controllers/GraphQLController.cs +++ b/src/AspNetWebApi/WebApi/Controllers/GraphQLController.cs @@ -47,7 +47,6 @@ public async Task PostAsync(HttpRequestMessage request, Gra _.Inputs = inputs; _.ComplexityConfiguration = new ComplexityConfiguration { MaxDepth = 15 }; - _.FieldMiddleware.Use(); }).ConfigureAwait(false); diff --git a/src/AspNetWebApi/WebApi/Web.config b/src/AspNetWebApi/WebApi/Web.config index d82bcfa..3e2fee5 100644 --- a/src/AspNetWebApi/WebApi/Web.config +++ b/src/AspNetWebApi/WebApi/Web.config @@ -1,303 +1,311 @@ - + - - - - + + + + + - - + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/AspNetWebApi/WebApi/WebApi.csproj b/src/AspNetWebApi/WebApi/WebApi.csproj index c20a442..d4b63a6 100644 --- a/src/AspNetWebApi/WebApi/WebApi.csproj +++ b/src/AspNetWebApi/WebApi/WebApi.csproj @@ -13,7 +13,7 @@ Properties WebApi WebApi - v4.6.1 + v4.8 false true @@ -24,6 +24,7 @@ + true @@ -44,34 +45,42 @@ 4 - - ..\packages\GraphQL.3.1.3\lib\netstandard2.0\GraphQL.dll + + ..\packages\GraphQL.4.7.1\lib\netstandard2.0\GraphQL.dll - - ..\packages\GraphQL-Parser.5.3.3\lib\netstandard2.0\GraphQL-Parser.dll + + ..\packages\GraphQL-Parser.7.2.0\lib\netstandard2.0\GraphQL-Parser.dll - - ..\packages\GraphQL.NewtonsoftJson.3.1.3\lib\netstandard2.0\GraphQL.NewtonsoftJson.dll + + ..\packages\GraphQL.NewtonsoftJson.4.7.1\lib\netstandard2.0\GraphQL.NewtonsoftJson.dll ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll - - ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll - ..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll + ..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + ..\packages\System.Reactive.4.4.1\lib\net46\System.Reactive.dll @@ -93,11 +102,11 @@ ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll + - - + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll @@ -124,7 +133,6 @@ - @@ -142,6 +150,7 @@ ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll + True ..\packages\WebGrease.1.6.0\lib\WebGrease.dll diff --git a/src/AspNetWebApi/WebApi/packages.config b/src/AspNetWebApi/WebApi/packages.config index f9a061e..e2bf15c 100644 --- a/src/AspNetWebApi/WebApi/packages.config +++ b/src/AspNetWebApi/WebApi/packages.config @@ -1,9 +1,9 @@  - - - + + + @@ -13,18 +13,20 @@ - + - + - + + + - + \ No newline at end of file diff --git a/src/AzureFunctions/Example/Example.csproj b/src/AzureFunctions/Example/Example.csproj index 257fa71..5c3a58f 100644 --- a/src/AzureFunctions/Example/Example.csproj +++ b/src/AzureFunctions/Example/Example.csproj @@ -1,13 +1,13 @@ - netcoreapp3.1 + net5 v3 enable - - - + + + diff --git a/src/AzureFunctions/Example/GraphQLExecuterExtensions.cs b/src/AzureFunctions/Example/GraphQLExecuterExtensions.cs index 8cd92e9..d58ce05 100644 --- a/src/AzureFunctions/Example/GraphQLExecuterExtensions.cs +++ b/src/AzureFunctions/Example/GraphQLExecuterExtensions.cs @@ -4,7 +4,7 @@ // https://github.com/tpeczek using GraphQL; using GraphQL.NewtonsoftJson; -using GraphQL.Server.Internal; +using GraphQL.Server; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; diff --git a/src/AzureFunctions/Example/StarWars.cs b/src/AzureFunctions/Example/StarWars.cs index 4837038..3a5993e 100644 --- a/src/AzureFunctions/Example/StarWars.cs +++ b/src/AzureFunctions/Example/StarWars.cs @@ -1,5 +1,5 @@ using GraphQL; -using GraphQL.Server.Internal; +using GraphQL.Server; using GraphQL.Types; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/src/AzureFunctions/Example/Startup.cs b/src/AzureFunctions/Example/Startup.cs index 2824e79..8656210 100644 --- a/src/AzureFunctions/Example/Startup.cs +++ b/src/AzureFunctions/Example/Startup.cs @@ -1,5 +1,4 @@ using GraphQL; -using GraphQL.Server; using GraphQL.Types; using Microsoft.Azure.Functions.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;