diff --git a/OttoTheGeek/ServiceCollectionExtensions.cs b/OttoTheGeek/ServiceCollectionExtensions.cs index 7ee0abc..9a71a1b 100644 --- a/OttoTheGeek/ServiceCollectionExtensions.cs +++ b/OttoTheGeek/ServiceCollectionExtensions.cs @@ -2,17 +2,19 @@ using System.Linq; using GraphQL; using GraphQL.DataLoader; -using GraphQL.Server; +using GraphQL.DI; +using GraphQL.Execution; +using GraphQLParser.AST; using Microsoft.Extensions.DependencyInjection; namespace OttoTheGeek { public static class ServiceCollectionExtensions { - public static IServiceCollection AddOtto(this IServiceCollection services, TModel model) + public static IServiceCollection AddOtto(this IServiceCollection services, TModel model, Action configureAction = null) where TModel : OttoModel { - services.TryRegisterGraphQLServer(); + services.TryRegisterGraphQLServer(configureAction); var ottoSchema = model.BuildOttoSchema(services); @@ -27,8 +29,9 @@ public static IServiceCollection AddOtto(this IServiceCollection service ; } - private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollection services) + private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollection services, Action configureAction) { + configureAction ??= NopConfigure; // using IDocumentExecuter to check for registration already present if (!services.Any(x => x.ServiceType == typeof(GraphQL.IDocumentExecuter))) { @@ -39,11 +42,13 @@ private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollecti .AddSystemTextJson() .AddGraphTypes() .AddDataLoader() + .AddExecutionStrategy(OperationType.Query) .ConfigureExecutionOptions(opts => { opts.EnableMetrics = false; }) ; + configureAction(builder); }); services .AddSingleton() @@ -52,5 +57,9 @@ private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollecti return services; } + + private static void NopConfigure(IGraphQLBuilder builder) + { + } } }