diff --git a/src/HotChocolate/Fusion/src/Composition.Analyzers/ConfigurationGenerator.cs b/src/HotChocolate/Fusion/src/Composition.Analyzers/ConfigurationGenerator.cs index ae180aef4ed..2e70acdd52f 100644 --- a/src/HotChocolate/Fusion/src/Composition.Analyzers/ConfigurationGenerator.cs +++ b/src/HotChocolate/Fusion/src/Composition.Analyzers/ConfigurationGenerator.cs @@ -188,6 +188,7 @@ private static void Execute( { if (syntaxInfos.Length == 0) { + WriteNoOpCompose(context); return; } @@ -223,8 +224,11 @@ private static void Execute( if (gateways.Count == 0) { + WriteNoOpCompose(context); return; } + + WriteCompose(context); var code = StringBuilderPool.Get(); using var writer = new CodeWriter(code); @@ -299,6 +303,30 @@ private static void Execute( context.AddSource("FusionConfiguration.g.cs", code.ToString()); StringBuilderPool.Return(code); } + + private static void WriteCompose(SourceProductionContext context) + { + var code = StringBuilderPool.Get(); + using var writer = new CodeWriter(code); + + writer.WriteFileHeader(); + writer.Write(AnalyzerResources.Compose); + + context.AddSource("FusionCompose.g.cs", code.ToString()); + StringBuilderPool.Return(code); + } + + private static void WriteNoOpCompose(SourceProductionContext context) + { + var code = StringBuilderPool.Get(); + using var writer = new CodeWriter(code); + + writer.WriteFileHeader(); + writer.Write(AnalyzerResources.NoOpCompose); + + context.AddSource("FusionCompose.g.cs", code.ToString()); + StringBuilderPool.Return(code); + } private static void AddInitializationContent(IncrementalGeneratorPostInitializationContext context) { diff --git a/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.Designer.cs b/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.Designer.cs index 470f8394c5c..8782a3b3a75 100644 --- a/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.Designer.cs +++ b/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.Designer.cs @@ -56,5 +56,17 @@ internal static string Extensions { return ResourceManager.GetString("Extensions", resourceCulture); } } + + internal static string NoOpCompose { + get { + return ResourceManager.GetString("NoOpCompose", resourceCulture); + } + } + + internal static string Compose { + get { + return ResourceManager.GetString("Compose", resourceCulture); + } + } } } diff --git a/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.resx b/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.resx index 0362e573398..51d3cd17857 100644 --- a/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.resx +++ b/src/HotChocolate/Fusion/src/Composition.Analyzers/Properties/AnalyzerResources.resx @@ -27,7 +27,6 @@ using System.Net.Mime; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; -using HotChocolate.Execution.Configuration; using HotChocolate.Fusion; using HotChocolate.Fusion.Composition; using HotChocolate.Fusion.Composition.Features; @@ -39,7 +38,6 @@ using Microsoft.Extensions.DependencyInjection; namespace HotChocolate.Fusion.Composition.Tooling { - internal static class FusionGatewayConfgHelper { public static async Task ConfigureAsync(CancellationToken cancellationToken = default) @@ -604,19 +602,6 @@ namespace Aspire.Hosting { internal static class FusionExtensions { - public static DistributedApplication Compose(this DistributedApplication application) - { - var options = application.Services.GetRequiredService<DistributedApplicationOptions>(); - - if (options.Args is ["compose"]) - { - global::HotChocolate.Fusion.Composition.Tooling.FusionGatewayConfgHelper.ConfigureAsync().Wait(); - Environment.Exit(0); - } - - return application; - } - public static IResourceBuilder<FusionGatewayResource> AddFusionGateway<TProject>( this IDistributedApplicationBuilder builder, string name) @@ -657,7 +642,42 @@ namespace Aspire.Hosting public FusionGatewayResource Resource { get; } = new(projectResourceBuilder.Resource); } -} - +} + + + using Microsoft.Extensions.DependencyInjection; + +namespace Aspire.Hosting +{ + internal static class DistributedApplicationExtensions + { + public static DistributedApplication Compose(this DistributedApplication application) + { + return application; + } + } +} + + + using Microsoft.Extensions.DependencyInjection; + +namespace Aspire.Hosting +{ + internal static class HotChocolateDistributedApplicationExtensions + { + public static DistributedApplication Compose(this DistributedApplication application) + { + var options = application.Services.GetRequiredService<DistributedApplicationOptions>(); + + if (options.Args is ["compose"]) + { + global::HotChocolate.Fusion.Composition.Tooling.FusionGatewayConfgHelper.ConfigureAsync().Wait(); + Environment.Exit(0); + } + + return application; + } + } +} \ No newline at end of file diff --git a/src/HotChocolate/Fusion/test/Composition.Analyzers.Tests/Program.cs b/src/HotChocolate/Fusion/test/Composition.Analyzers.Tests/Program.cs index 373ca42bff6..970ef9805d6 100644 --- a/src/HotChocolate/Fusion/test/Composition.Analyzers.Tests/Program.cs +++ b/src/HotChocolate/Fusion/test/Composition.Analyzers.Tests/Program.cs @@ -62,17 +62,16 @@ public static void Foo(string[] args) .WithEnvironment("Identity__Url", identityHttpsEndpoint); // Fusion - builder + var gateway = builder .AddFusionGateway("gateway") .WithSubgraph(basketApi) - .WithSubgraph(identityApi.GetEndpoint("http")) + .WithSubgraph(identityApi) .WithSubgraph(catalogApi) .WithSubgraph(orderingApi) - .WithSubgraph(purchaseApi) - .WithEnvironment("Identity__Url", identityHttpsEndpoint); - + .WithSubgraph(purchaseApi); builder.Build().Compose().Run(); } } +