Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the apply extensions middleware. (#5151)
- Loading branch information
1 parent
74f5a82
commit e40f6a3
Showing
5 changed files
with
118 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ate/Stitching/src/Stitching.Types/Pipeline/PrepareDocuments/PrepareDocumentsMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.