|
3 | 3 | using HotChocolate.Fusion.Configuration; |
4 | 4 | using HotChocolate.Fusion.Execution; |
5 | 5 | using HotChocolate.Fusion.Execution.Clients; |
| 6 | +using HotChocolate.Language; |
6 | 7 | using Microsoft.Extensions.DependencyInjection.Extensions; |
7 | 8 | using Microsoft.Extensions.ObjectPool; |
8 | 9 | using Microsoft.Extensions.Options; |
@@ -74,7 +75,30 @@ private static DefaultFusionGatewayBuilder CreateBuilder( |
74 | 75 | } |
75 | 76 |
|
76 | 77 | var builder = new DefaultFusionGatewayBuilder(services, name); |
| 78 | + builder.AddDocumentCache(); |
77 | 79 | builder.UseDefaultPipeline(); |
78 | 80 | return builder; |
79 | 81 | } |
| 82 | + |
| 83 | + private static IFusionGatewayBuilder AddDocumentCache(this IFusionGatewayBuilder builder) |
| 84 | + { |
| 85 | + builder.Services.TryAddKeyedSingleton<IDocumentCache>( |
| 86 | + builder.Name, |
| 87 | + static (sp, schemaName) => |
| 88 | + { |
| 89 | + var optionsMonitor = sp.GetRequiredService<IOptionsMonitor<FusionGatewaySetup>>(); |
| 90 | + var setup = optionsMonitor.Get((string)schemaName!); |
| 91 | + |
| 92 | + var options = FusionRequestExecutorManager.CreateOptions(setup); |
| 93 | + |
| 94 | + return new DefaultDocumentCache(options.OperationDocumentCacheSize); |
| 95 | + }); |
| 96 | + |
| 97 | + return builder.ConfigureSchemaServices( |
| 98 | + static (sp, s) => s.AddSingleton<IDocumentCache>(schemaServices => |
| 99 | + { |
| 100 | + var schemaName = schemaServices.GetRequiredService<ISchemaDefinition>().Name; |
| 101 | + return sp.GetRequiredKeyedService<IDocumentCache>(schemaName); |
| 102 | + })); |
| 103 | + } |
80 | 104 | } |
0 commit comments