-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphQLServerModuleCollection.cs
More file actions
38 lines (35 loc) · 1.62 KB
/
GraphQLServerModuleCollection.cs
File metadata and controls
38 lines (35 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using HotChocolate.AspNetCore.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Modulight.Modules.Hosting;
namespace Modulight.Modules.Server.GraphQL
{
/// <summary>
/// Specifies the contract for graphql module hosts.
/// </summary>
public interface IGraphQLServerModuleCollection : IModuleCollection<IGraphQLServerModule, GraphQLServerModuleManifest>
{
/// <summary>
/// Map all registered module's endpoints.
/// Used in <see cref="EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder, Action{IEndpointRouteBuilder})"/>.
/// </summary>
/// <param name="builder"></param>
/// <param name="postMapEndpoint">Action to configure mapped GraphQL endpoints.</param>
void MapEndpoints(IEndpointRouteBuilder builder, Action<IGraphQLServerModule, GraphQLEndpointConventionBuilder>? postMapEndpoint = null);
}
internal class GraphQLServerModuleCollection : ModuleHostFilterCollection<IGraphQLServerModule, GraphQLServerModuleManifest>, IGraphQLServerModuleCollection
{
public GraphQLServerModuleCollection(IModuleHost host) : base(host)
{
}
public void MapEndpoints(IEndpointRouteBuilder builder, Action<IGraphQLServerModule, GraphQLEndpointConventionBuilder>? postMapEndpoint = null)
{
foreach (var module in LoadedModules)
{
var gbuilder = module.MapEndpoint(builder);
if (gbuilder is not null && postMapEndpoint is not null)
postMapEndpoint(module, gbuilder);
}
}
}
}