This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add graphql api gateway (#240)
* graphql gateway implementation * update readme
- Loading branch information
1 parent
16abcfe
commit dc0e813
Showing
12 changed files
with
262 additions
and
4 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
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
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,39 @@ | ||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build | ||
WORKDIR /src | ||
|
||
COPY "eSchool.sln" "eSchool.sln" | ||
|
||
COPY "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" | ||
|
||
COPY "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" | ||
COPY "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" | ||
COPY "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" | ||
COPY "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" | ||
COPY "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj" "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj" | ||
|
||
COPY "src/Libraries/OpenTelemetry/OpenTelemetry.csproj" "src/Libraries/OpenTelemetry/OpenTelemetry.csproj" | ||
|
||
COPY "src/Web/WebStatus/WebStatus.csproj" "src/Web/WebStatus/WebStatus.csproj" | ||
|
||
COPY "docker-compose.dcproj" "docker-compose.dcproj" | ||
|
||
RUN dotnet restore eSchool.sln -nowarn:msb3202,nu1503 | ||
|
||
COPY . . | ||
WORKDIR /src/src/ApiGateways/eSchool.GraphQL | ||
RUN dotnet build --no-restore -c Release -o /app/build | ||
|
||
FROM build as unittest | ||
WORKDIR /src/src/Services/Enrolling/Enrolling.UnitTests | ||
|
||
FROM build AS publish | ||
RUN dotnet publish --no-restore -c Release -o /app/publish | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "ESchool.GraphQL.dll"] |
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,80 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Serilog; | ||
using Serilog.Enrichers.Span; | ||
|
||
namespace OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL | ||
{ | ||
public class Program | ||
{ | ||
public static readonly string Namespace = typeof(Program).Namespace!; | ||
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1); | ||
|
||
public static int Main(string[] args) | ||
{ | ||
Activity.DefaultIdFormat = ActivityIdFormat.W3C; | ||
|
||
var configuration = GetConfiguration(); | ||
|
||
Log.Logger = CreateSerilogLogger(configuration); | ||
|
||
try | ||
{ | ||
Log.Information("Configuring web host ({ApplicationContext})...", AppName); | ||
var host = CreateHostBuilder(configuration, args).Build(); | ||
|
||
Log.Information("Starting web host ({ApplicationContext})...", AppName); | ||
host.Run(); | ||
|
||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(IConfiguration configuration, string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
webBuilder.UseConfiguration(configuration); | ||
webBuilder.UseSerilog(); | ||
}); | ||
|
||
|
||
private static ILogger CreateSerilogLogger(IConfiguration configuration) | ||
{ | ||
return new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.Enrich.WithProperty("ApplicationContext", AppName) | ||
.Enrich.FromLogContext() | ||
.Enrich.WithSpan() | ||
.WriteTo.Console() | ||
.WriteTo.Seq("http://seq") | ||
.ReadFrom.Configuration(configuration) | ||
.CreateLogger(); | ||
} | ||
|
||
private static IConfiguration GetConfiguration() | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.AddEnvironmentVariables(); | ||
|
||
// Load other configurations here. Ex. Keyvault or AppConfiguration | ||
return builder.Build(); | ||
} | ||
} | ||
} |
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,47 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using OpenCodeFoundation.OpenTelemetry; | ||
using Serilog; | ||
|
||
namespace OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL | ||
{ | ||
public class Startup | ||
{ | ||
public const string Enrolling = "enrolling"; | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddHttpClient(Enrolling, c => | ||
c.BaseAddress = new Uri("http://enrolling.api/graphql")); | ||
|
||
services | ||
.AddGraphQLServer() | ||
.AddRemoteSchema(Enrolling); | ||
|
||
services.AddOpenTelemetryIntegration(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseSerilogRequestLogging(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapGraphQL(); | ||
}); | ||
} | ||
} | ||
} |
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,23 @@ | ||
{ | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Information", | ||
"Override": { | ||
"Microsoft": "Warning", | ||
"OpenCodeFoundation": "Information", | ||
"System": "Warning" | ||
} | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"OpenTelemetry": { | ||
"Enabled": true, | ||
"Istio": false, | ||
"Jaeger": { | ||
"Enabled": true, | ||
"ServiceName": "eschool.graphql", | ||
"Host": "jaeger", | ||
"Port": 6831 | ||
} | ||
} | ||
} |
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<AssemblyName>ESchool.GraphQL</AssemblyName> | ||
<RootNamespace>OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL</RootNamespace> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="HotChocolate.AspNetCore" Version="11.0.0" /> | ||
<PackageReference Include="HotChocolate.Stitching" Version="11.0.0" /> | ||
|
||
<!-- Logging --> | ||
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" /> | ||
<PackageReference Include="Serilog.Enrichers.Span" Version="1.0.1" /> | ||
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Libraries\OpenTelemetry\OpenTelemetry.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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