Skip to content

Commit

Permalink
Fixes #2879 (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetski5822 authored Jan 22, 2019
1 parent e16bb08 commit c39faf3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class GraphQLSettings
{
public PathString Path { get; set; } = "/api/graphql";
public Func<HttpContext, object> BuildUserContext { get; set; }
public bool ExposeExceptions = false;
}
}
19 changes: 17 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IDependencyResolver, RequestServicesDependencyResolver>();
Expand All @@ -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<bool>($"Modules:OrchardCore.Apis.GraphQL:{nameof(GraphQLSettings.ExposeExceptions)}", true);
#else
var exposeExceptions = _configuration.GetValue<bool>($"Modules:OrchardCore.Apis.GraphQL:{nameof(GraphQLSettings.ExposeExceptions)}", false);
#endif

app.UseMiddleware<GraphQLMiddleware>(new GraphQLSettings
{
BuildUserContext = ctx => new GraphQLContext
{
User = ctx.User,
ServiceProvider = ctx.RequestServices
}
ServiceProvider = ctx.RequestServices,
},
ExposeExceptions = exposeExceptions
});
}
}
Expand Down

0 comments on commit c39faf3

Please sign in to comment.