-
-
Notifications
You must be signed in to change notification settings - Fork 723
/
PrepareDocumentsMiddleware.cs
55 lines (44 loc) · 1.52 KB
/
PrepareDocumentsMiddleware.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using HotChocolate.Language;
namespace HotChocolate.Stitching.Types.Pipeline.PrepareDocuments;
public class PrepareDocumentsMiddleware
{
private readonly MergeSchema _next;
public PrepareDocumentsMiddleware(MergeSchema next)
{
_next = next;
}
public async ValueTask InvokeAsync(ISchemaMergeContext context)
{
foreach (ServiceConfiguration configuration in context.Configurations)
{
var definitions = new List<IDefinitionNode>();
RegisterServiceInfo(definitions, configuration);
foreach (DocumentNode document in configuration.Documents)
{
foreach (IDefinitionNode definition in document.Definitions)
{
definitions.Add(definition);
}
}
context.Documents = context.Documents.Add(
new Document(configuration.Name, new DocumentNode(definitions)));
}
await _next(context);
}
private static void RegisterServiceInfo(
List<IDefinitionNode> definitions,
ServiceConfiguration configuration)
{
var serviceName = new DirectiveNode(
"_hc_service",
new ArgumentNode("name", configuration.Name));
var serviceInfo = new SchemaExtensionNode(
null,
new[] { serviceName },
Array.Empty<OperationTypeDefinitionNode>());
definitions.Add(serviceInfo);
}
}