Skip to content

Commit

Permalink
pass through config delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
floyd-may committed Feb 17, 2023
1 parent 377e04f commit 91f636f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions OttoTheGeek/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TModel>(this IServiceCollection services, TModel model)
public static IServiceCollection AddOtto<TModel>(this IServiceCollection services, TModel model, Action<IGraphQLBuilder> configureAction = null)
where TModel : OttoModel
{
services.TryRegisterGraphQLServer();
services.TryRegisterGraphQLServer(configureAction);

var ottoSchema = model.BuildOttoSchema(services);

Expand All @@ -27,8 +29,9 @@ public static IServiceCollection AddOtto<TModel>(this IServiceCollection service
;
}

private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollection services)
private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollection services, Action<IGraphQLBuilder> configureAction)
{
configureAction ??= NopConfigure;
// using IDocumentExecuter to check for registration already present
if (!services.Any(x => x.ServiceType == typeof(GraphQL.IDocumentExecuter)))
{
Expand All @@ -39,11 +42,13 @@ private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollecti
.AddSystemTextJson()
.AddGraphTypes()
.AddDataLoader()
.AddExecutionStrategy<SerialExecutionStrategy>(OperationType.Query)
.ConfigureExecutionOptions(opts =>
{
opts.EnableMetrics = false;
})
;
configureAction(builder);
});
services
.AddSingleton<IDocumentExecuter, Internal.OttoDocumentExecuter>()
Expand All @@ -52,5 +57,9 @@ private static IServiceCollection TryRegisterGraphQLServer(this IServiceCollecti

return services;
}

private static void NopConfigure(IGraphQLBuilder builder)
{
}
}
}

0 comments on commit 91f636f

Please sign in to comment.