From c114e2f9485aafa28aca3758e919bf88a6b82fb9 Mon Sep 17 00:00:00 2001 From: Nick Mayne Date: Tue, 22 Jan 2019 13:23:18 +0000 Subject: [PATCH] Fixes #2879 --- .../GraphQLMiddleware.cs | 5 +---- .../GraphQLSettings.cs | 1 + .../OrchardCore.Apis.GraphQL/Startup.cs | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs index d83635d0f60..1e4670e880b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs @@ -164,10 +164,7 @@ private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaServic _.OperationName = request.OperationName; _.Inputs = request.Variables.ToInputs(); _.UserContext = _settings.BuildUserContext?.Invoke(context); - -#if DEBUG - _.ExposeExceptions = true; -#endif + _.ExposeExceptions = _settings.ExposeExceptions; }); var httpResult = result.Errors?.Count > 0 diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLSettings.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLSettings.cs index ef858ef3afd..b795caabe96 100644 --- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLSettings.cs +++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLSettings.cs @@ -7,5 +7,6 @@ public class GraphQLSettings { public PathString Path { get; set; } = "/api/graphql"; public Func BuildUserContext { get; set; } + public bool ExposeExceptions = false; } } \ No newline at end of file diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Startup.cs index f0b513dcfed..3c2f9026d59 100644 --- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Startup.cs @@ -3,6 +3,7 @@ using GraphQL.Http; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using OrchardCore.Apis.GraphQL.Services; using OrchardCore.Modules; @@ -13,6 +14,13 @@ namespace OrchardCore.Apis.GraphQL { public class Startup : StartupBase { + private IConfiguration _configuration; + + public Startup(IConfiguration configuration) + { + _configuration = configuration; + } + public override void ConfigureServices(IServiceCollection services) { services.AddSingleton(); @@ -27,13 +35,20 @@ public override void ConfigureServices(IServiceCollection services) public override void Configure(IApplicationBuilder app, IRouteBuilder routes, IServiceProvider serviceProvider) { +#if DEBUG + var exposeExceptions = _configuration.GetValue($"Modules:OrchardCore.Apis.GraphQL:{nameof(GraphQLSettings.ExposeExceptions)}", true); +#else + var exposeExceptions = _configuration.GetValue($"Modules:OrchardCore.Apis.GraphQL:{nameof(GraphQLSettings.ExposeExceptions)}", false); +#endif + app.UseMiddleware(new GraphQLSettings { BuildUserContext = ctx => new GraphQLContext { User = ctx.User, - ServiceProvider = ctx.RequestServices - } + ServiceProvider = ctx.RequestServices, + }, + ExposeExceptions = exposeExceptions }); } }