elsa-core/src/server/Elsa.Server.GraphQL/Extensions/GraphQLServiceCollectionExtensions.cs

58 lines
2.1 KiB
C#
Raw Normal View History

2019-11-22 22:07:31 +00:00
using System;
using Elsa;
using Elsa.AutoMapper.Extensions;
using Elsa.Models;
2019-11-22 22:07:31 +00:00
using Elsa.Server.GraphQL;
2019-11-23 14:08:40 +00:00
using Elsa.Server.GraphQL.Mapping;
2019-11-24 21:02:14 +00:00
using Elsa.Server.GraphQL.Mutations;
using Elsa.Server.GraphQL.Queries;
using Elsa.Server.GraphQL.Services;
using GraphQL.NodaTime;
2019-11-22 22:07:31 +00:00
using GraphQL.Server;
using GraphQL.Types;
2019-11-22 22:07:31 +00:00
2019-11-23 14:08:40 +00:00
// ReSharper disable once CheckNamespace
2019-11-22 22:07:31 +00:00
namespace Microsoft.Extensions.DependencyInjection
{
public static class GraphQLServiceCollectionExtensions
{
public static ElsaBuilder AddGraphQL(this ElsaBuilder builder, Action<GraphQLOptions> configure = null)
{
var services = builder.Services;
services
.AddScoped<ElsaSchema>()
.AddSingleton<InstantGraphType>()
.AddSingleton<EnumerationGraphType<WorkflowStatus>>()
2019-11-24 21:02:14 +00:00
.AddQueryProvider<ListWorkflowDefinitions>()
.AddQueryProvider<ListWorkflowInstances>()
.AddQueryProvider<GetWorkflowDefinition>()
.AddMutationProvider<DefineWorkflow>()
.AddMutationProvider<UpdateWorkflowDefinition>()
.AddMutationProvider<RunWorkflow>()
.AddMutationProvider<PublishWorkflow>()
.AddMutationProvider<DeleteWorkflowDefinition>()
2019-11-23 14:08:40 +00:00
.AddAutoMapperProfile<GraphQLProfile>(ServiceLifetime.Singleton)
2019-11-22 22:07:31 +00:00
.AddLogging();
var graphQLOptions = new GraphQLOptions();
configure?.Invoke(graphQLOptions);
services
.AddGraphQL(graphQLOptions)
.AddGraphTypes(ServiceLifetime.Scoped);
return builder;
}
2019-11-24 21:02:14 +00:00
public static IServiceCollection AddMutationProvider<T>(this IServiceCollection services) where T : class, IMutationProvider
{
return services.AddScoped<IMutationProvider, T>();
}
public static IServiceCollection AddQueryProvider<T>(this IServiceCollection services) where T : class, IQueryProvider
{
return services.AddScoped<IQueryProvider, T>();
}
2019-11-22 22:07:31 +00:00
}
}