Skip to content

HotChocolate.Fusion.Aspire hides annotations (such as endpoints) on gateway project #7544

@csboling

Description

@csboling

Product

Hot Chocolate

Version

15.0.0-p.3

Link to minimal reproduction

https://github.com/csboling/hotchocolate-aspire-fusion-annotations

Steps to reproduce

  • Run the AppHost.
  • View the dashboard at http://localhost:15053. The "downstream" project has failed to start.
  • View the logs for the "downstream" project. The error message is: "Failed to apply configuration value 'MY_GATEWAY'. A dependency may have failed to start." This is because the environment variable annotations cannot be accessed from the FusionGatewayResourceBuilder.

image

Code snippet from AppHost's Program.cs:

var builder = DistributedApplication.CreateBuilder(args);

var subgraph = builder.AddProject<Projects.Subgraph>("subgraph");
var gateway = builder.AddFusionGateway<Projects.Gateway>("gateway")
    .WithSubgraph(subgraph)
    .WithExternalHttpEndpoints();

// this server will fail to start because it tries to use an endpoint from `gateway`
var downstream = builder.AddProject<Projects.Downstream>("downstream")
    .WithEnvironment("MY_GATEWAY", gateway.GetEndpoint("http"));

builder.Build().Compose().Run();

What is expected?

The IResourceBuilder<FusionGatewayResource> returned by IDistributedApplicationBuilder.AddFusionGateway<TProject>(name) should be usable as an IResourceBuilder elsewhere in the Aspire configuration, e.g. it should be possible to inject endpoints into other projects using .WithEnvironment("MY_GATEWAY", gateway.GetEndpoint("http")) or .WithReference(gateway).

What is actually happening?

With .WithReference(gateway), the expected environment variable service__gateway__http__0 is not injected into the dependent project. With .WithEnvironment("MY_GATEWAY", gateway.GetEndpoint("http")) the dependent project does not start at all, because the annotation for the endpoint cannot be found.

Relevant log output

No response

Additional context

This happens because FusionGatewayResourceBuilder forwards WithAnnotation calls to the wrapped ProjectResourceBuilder, so the FusionGatewayResourceBuilder object does not contain any annotations itself -- the FusionGatewayResourceBuilder.Annotations collection is always empty. Since the wrapped ProjectResourceBuilder inside the FusionGatewayResourceBuilder is not exposed, there is no way to access the annotations collection in other Aspire code.

Possible fix: Modify FusionGatewayResource to add

public override ResourceAnnotationCollection Annotations => projectResource.Annotations;

This allows other Aspire extension methods that operate on IResourceBuilder<> to access the annotations in the wrapped projectResource, allowing scenarios such as the example repository to work correctly. Currently it seems that FusionGatewayResourceBuilder passes along the "write side" of modifying the annotation collection, but there is nothing passing along the "read side" in FusionGatewayResource.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions