30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using FictionArchive.Service.Shared.Services.GraphQL;
|
|
using HotChocolate.Execution.Configuration;
|
|
using HotChocolate.Types.NodaTime;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace FictionArchive.Service.Shared.Extensions;
|
|
|
|
public static class GraphQLExtensions
|
|
{
|
|
public static IRequestExecutorBuilder AddDefaultGraphQl<TQuery, TMutation>(this IServiceCollection services) where TQuery : class where TMutation : class
|
|
{
|
|
return services.AddGraphQLServer()
|
|
.AddQueryType<TQuery>()
|
|
.AddMutationType<TMutation>()
|
|
.ApplySaneDefaults();
|
|
|
|
}
|
|
|
|
public static IRequestExecutorBuilder ApplySaneDefaults(this IRequestExecutorBuilder builder)
|
|
{
|
|
return builder.AddDiagnosticEventListener<ErrorEventListener>()
|
|
.AddErrorFilter<LoggingErrorFilter>()
|
|
.AddType<UnsignedIntType>()
|
|
.AddType<InstantType>()
|
|
.AddMutationConventions(applyToAllMutations: true)
|
|
.AddFiltering(opt => opt.AddDefaults().BindRuntimeType<uint, UnsignedIntOperationFilterInputType>())
|
|
.AddSorting()
|
|
.AddProjections();
|
|
}
|
|
} |