Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Aspire.AppHost.Sdk/13.1.0">
<Project Sdk="Aspire.AppHost.Sdk/13.1.1">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this change as we should keep them all in sync and we haven't had time to update everything else.


<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -15,13 +15,17 @@

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder\CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.McpInspector\CommunityToolkit.Aspire.Hosting.McpInspector.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.BlazorApp\CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.BlazorApp.csproj" />
</ItemGroup>

<ItemGroup>
<None Update=".\dab-config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update=".\sql-server.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
var builder = DistributedApplication.CreateBuilder(args);

// Add a SQL Server container
var sqlServer = builder
.AddSqlServer("sql");
var sqlScript = File.ReadAllText("./sql-server.sql");

var sqlDatabase = sqlServer.AddDatabase("trek");
var sqlDatabase = builder
.AddSqlServer("sql")
.WithDataVolume("trek-sql-data")
.AddDatabase("trek")
.WithCreationScript(sqlScript);

// Populate the database with the schema and data
sqlServer
.WithBindMount("./sql-server", target: "/usr/config")
.WithBindMount("../database", target: "/docker-entrypoint-initdb.d")
.WithEntrypoint("/usr/config/entrypoint.sh");
var dabConfig = new FileInfo("./dab-config.json");

// Add Data API Builder using dab-config.json
var dab = builder.AddDataAPIBuilder("dab")
.WaitFor(sqlServer)
.WithImageTag("1.7.86-rc")
.WithConfigFile(dabConfig)
.WaitFor(sqlDatabase)
.WithReference(sqlDatabase);

var mcp = builder
.AddMcpInspector("mcp-inspector", options =>
{
options.InspectorVersion = "0.20.0";
})
.WithMcpServer(dab, transportType: McpTransportType.StreamableHttp)
.WithParentRelationship(dab)
.WithEnvironment("DANGEROUSLY_OMIT_AUTH", "true")
.WaitFor(dab);

builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Azure_DataApiBuilder_BlazorApp>("blazorApp")
.WithReference(dab);
.WithReference(dab)
.WaitFor(dab);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.3.19/dab.draft.schema.json",
"$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.7.86-rc/dab.draft.schema.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the container image listed, shouldn't they match?

"data-source": {
"database-type": "mssql",
"connection-string": "@env('ConnectionStrings__trek')",
Expand All @@ -16,6 +16,9 @@
"path": "/graphql",
"allow-introspection": true
},
"mcp": {
"enabled": true
},
"host": {
"cors": {
"origins": [
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

<PageTitle>Home</PageTitle>

<h1>Aspire Data API Builder Integration</h1>

<h3>Welcome to your demo app 🖖</h3>
<h1>Data API Builder</h1>

@if (series is null)
{
<p>Loading...</p>
}
else
{
<h5>Here some StarTrek series</h5>
<h5>Here are some Star Trek series 🖖</h5>
<ul>
@foreach (var s in series)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "CA1873:Avoid potentially expensive logging", Justification = "The additional allocation cost from logging in TrekApiClient.GetSeriesAsync is acceptable for this sample Blazor application and simplifies the example code.", Scope = "member", Target = "~M:CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.BlazorApp.TrekApiClient.GetSeriesAsync~System.Threading.Tasks.Task{System.Collections.Generic.List{CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.BlazorApp.Series}}")]
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
using System.Net.Http;
using System.Text.Json.Serialization;
using System.Text.Json;

using System.Text.Json.Serialization;

namespace CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.BlazorApp;

public class TrekApiClient
public class TrekApiClient(HttpClient httpClient, ILogger<TrekApiClient> logger)
{
private readonly HttpClient httpClient;
private readonly ILogger<TrekApiClient> logger;

public TrekApiClient(HttpClient httpClient, ILogger<TrekApiClient> logger)
{
this.httpClient = httpClient;
this.logger = logger;
}

public async Task<List<Series>> GetSeriesAsync()
{
try
var response = await httpClient.GetAsync($"api/series");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<DabResponse<Series>>();

if(result is null)
{
var result = await httpClient.GetFromJsonAsync<SeriesList>($"api/series");
return result?.value ?? new List<Series>();
logger.LogError("Failed to deserialize response from Data API Builder.");
throw new Exception("Failed to deserialize response from Data API Builder.");
}
catch (Exception ex)

if (result.Error is not null)
{
logger.LogError(ex, "An error occurred while fetching series.");
return new List<Series>();
logger.LogError("API error: {Code} - {Message}", result.Error.Code, result.Error.Message);
throw new Exception($"{result.Error.Code}: {result.Error.Message}");
}

return result.Value ?? [];
}
}

public class SeriesList
public class DabResponse<T>
{
public List<Series> value { get; set; } = new List<Series>();
[JsonPropertyName("value")]
public List<T>? Value { get; set; }

[JsonPropertyName("nextLink")]
public string? NextLink { get; set; }

[JsonPropertyName("error")]
public DabError? Error { get; set; }
}

public class DabError
{
[JsonPropertyName("code")]
public string Code { get; set; } = string.Empty;

[JsonPropertyName("message")]
public string Message { get; set; } = string.Empty;

[JsonPropertyName("status")]
public int Status { get; set; }
}

public class Series
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public int Id { get; set; }
public required string Name { get; set; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more health checks?

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
namespace CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder;

/// <summary>
/// Container image tags for the Data API Builder container.
/// </summary>
internal static class DataApiBuilderContainerImageTags
{
/// <summary>The container registry.</summary>
public const string Registry = "mcr.microsoft.com";

/// <summary>The container image name.</summary>
public const string Image = "azure-databases/data-api-builder";
public const string Tag = "1.6.77";

/// <summary>The default container image tag.</summary>
public const string Tag = "1.6.87";
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// A resource that represents Data Api Builder.
/// A resource that represents Data API Builder.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="entrypoint">An optional container entrypoint.</param>

public class DataApiBuilderContainerResource(string name, string? entrypoint = null)
public sealed class DataApiBuilderContainerResource(string name, string? entrypoint = null)
: ContainerResource(name, entrypoint), IResourceWithServiceDiscovery
{
internal const string HttpEndpointName = "http";
internal const string HttpsEndpointName = "https";

internal const int HttpEndpointPort = 5000;
internal const int HttpsEndpointPort = 5001;

private EndpointReference? _primaryEndpoint;

/// <summary>
/// Gets the primary HTTP endpoint for the Data API Builder container.
/// </summary>
public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, HttpEndpointName);
}
Loading
Loading