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

[GraphQL] configure expose exceptions from configuration Fixes #2879 #3077

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Jetski5822 marked this conversation as resolved.
Show resolved Hide resolved
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