Skip to content

Commit

Permalink
feat: Added option to throw on schema error
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed Feb 6, 2022
1 parent c4fa00f commit 519b89d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Nikcio.UHeadless/Extentions/Startup/UHeadlessExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HotChocolate.Execution.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Nikcio.UHeadless.Factories.Properties;
using Nikcio.UHeadless.Factories.Properties.PropertyValues;
using Nikcio.UHeadless.Factories.Reflection;
Expand All @@ -21,7 +22,7 @@ namespace Nikcio.UHeadless.Extentions.Startup
{
public static class UHeadlessExtentions
{
public static IUmbracoBuilder AddUHeadless(this IUmbracoBuilder builder, List<Assembly> automapperAssemblies = null, List<Action<IPropertyMap>> customPropertyMappings = null)
public static IUmbracoBuilder AddUHeadless(this IUmbracoBuilder builder, List<Assembly> automapperAssemblies = null, List<Action<IPropertyMap>> customPropertyMappings = null, bool throwOnSchemaError = false)
{
builder.Services.AddUHeadlessAutomapper(automapperAssemblies);

Expand All @@ -35,7 +36,7 @@ public static IUmbracoBuilder AddUHeadless(this IUmbracoBuilder builder, List<As

builder.Services
.AddGraphQLServer()
.AddUHeadlessGraphQL();
.AddUHeadlessGraphQL(throwOnSchemaError);

return builder;
}
Expand Down Expand Up @@ -75,13 +76,18 @@ private static IServiceCollection AddUHeadlessAutomapper(this IServiceCollection
return services;
}

public static IRequestExecutorBuilder AddUHeadlessGraphQL(this IRequestExecutorBuilder requestExecutorBuilder)
public static IRequestExecutorBuilder AddUHeadlessGraphQL(this IRequestExecutorBuilder requestExecutorBuilder, bool throwOnSchemaError = false)
{
requestExecutorBuilder
.InitializeOnStartup()
.OnSchemaError(new OnSchemaError((dc, ex) =>
{
throw ex;
var logger = dc.Services.GetService<ILogger<Query>>();
logger.LogError(ex, "Schema failed to generate. GraphQL is unavalible");
if (throwOnSchemaError)
{
throw ex;
}
}))
.AddQueryType<Query>()
.AddTypeExtension<ContentQuery>()
Expand All @@ -100,8 +106,7 @@ public static IRequestExecutorBuilder AddUHeadlessGraphQL(this IRequestExecutorB

public static IApplicationBuilder UseUHeadlessGraphQLEndpoint(this IApplicationBuilder applicationBuilder, string corsPolicy = null)
{
applicationBuilder
.UseRouting();
applicationBuilder.UseRouting();

if (corsPolicy != null)
{
Expand Down

0 comments on commit 519b89d

Please sign in to comment.