Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit dc0e813

Browse files
authored
feat: add graphql api gateway (#240)
* graphql gateway implementation * update readme
1 parent 16abcfe commit dc0e813

12 files changed

Lines changed: 262 additions & 4 deletions

File tree

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,32 @@ $ docker-compose up
3636
in terminal from project's root folder. The first run can take 30 mins to 1 hour depending on your internet speed, as it will download required docker images from the docker hub. After everything starts up, you can access the `Enrolling.API` swagger UI by visiting [http://localhost:5102/swagger/](http://localhost:5102/swagger/)
3737

3838
### Service URLs
39-
* WebStatus - [http://localhost:5107/](http://localhost:5107/)
40-
* Enrolling.API - [http://localhost:5102/swagger/](http://localhost:5102/swagger/)
4139

40+
- eSchool Gateway (GraphQL) - [http://localhost:5101/graphql/](http://localhost:5102/graphql/)
41+
- WebStatus - [http://localhost:5107/](http://localhost:5107/)
42+
- Enrolling.API (REST - Swagger) - [http://localhost:5102/swagger/](http://localhost:5102/swagger/)
43+
- Enrolling.API (GraphQL - Banana Cake Pop) - [http://localhost:5102/graphql/](http://localhost:5102/graphql/)
44+
- Distributed Tracing (Jaeger) - [http://localhost:16686](http://localhost:16686)
45+
- Logging (Seq) - [http://localhost:5140/](http://localhost:5140/)
4246

4347
## Tech & Tools
48+
4449
- .NET Core
4550
- Docker
4651
- Orchestrators: Kubernetes
4752
- Visual Studio
48-
- MongoDB
4953
- SQL Server
5054
- Azure DevOps
51-
- Redis
5255
- RabbitMQ
56+
- API Gateway
57+
- GraphQL
5358

5459
## Contributing
60+
5561
Everyone is welcome to contribute, whether it's in the form of code, documentation, bug reports, feature requests, or anything else. See the [Contributing](https://github.com/OpenCodeFoundation/eschool/blob/master/CONTRIBUTING.md) guide for more details.
5662

5763
## Sending feedback and pull requests
64+
5865
As mentioned, we'd appreciate your feedback, improvements and ideas.
5966
You can create new issues at the issues section, do pull requests and/or send emails to **techcombd@outlook.com**
6067

@@ -63,4 +70,5 @@ You can create new issues at the issues section, do pull requests and/or send em
6370
[![contributors](https://contributors-img.web.app/image?repo=OpenCodeFoundation/eSchool)](https://github.com/OpenCodeFoundation/eSchool/graphs/contributors)
6471

6572
## License
73+
6674
Code licensed under the [MIT License](https://github.com/OpenCodeFoundation/eSchool/blob/master/LICENSE).

docker-compose.override.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ services:
3333
ports:
3434
- "5107:80"
3535

36+
eschool.graphql:
37+
environment:
38+
- ASPNETCORE_ENVIRONMENT=Production
39+
- ASPNETCORE_URLS=http://0.0.0.0:80
40+
ports:
41+
- "5101:80"
42+
3643
jaeger:
3744
environment:
3845
- COLLECTOR_ZIPKIN_HTTP_PORT=9411

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ services:
2121
context: .
2222
dockerfile: src/Web/WebStatus/Dockerfile
2323

24+
eschool.graphql:
25+
image: ${REGISTRY:-eschool}/eschool.graphql:${TAG:-latest}
26+
build:
27+
context: .
28+
dockerfile: src/ApiGateways/eSchool.GraphQL/Dockerfile
29+
2430
jaeger:
2531
image: jaegertracing/all-in-one

eSchool.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{
2929
EndProject
3030
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}"
3131
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateways", "ApiGateways", "{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}"
33+
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}"
35+
EndProject
3236
Global
3337
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3438
Debug|Any CPU = Debug|Any CPU
@@ -135,6 +139,18 @@ Global
135139
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}.Release|x64.Build.0 = Release|Any CPU
136140
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}.Release|x86.ActiveCfg = Release|Any CPU
137141
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}.Release|x86.Build.0 = Release|Any CPU
142+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
143+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
144+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x64.ActiveCfg = Debug|Any CPU
145+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x64.Build.0 = Debug|Any CPU
146+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x86.ActiveCfg = Debug|Any CPU
147+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x86.Build.0 = Debug|Any CPU
148+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
149+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|Any CPU.Build.0 = Release|Any CPU
150+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x64.ActiveCfg = Release|Any CPU
151+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x64.Build.0 = Release|Any CPU
152+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x86.ActiveCfg = Release|Any CPU
153+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x86.Build.0 = Release|Any CPU
138154
EndGlobalSection
139155
GlobalSection(SolutionProperties) = preSolution
140156
HideSolutionNode = FALSE
@@ -151,6 +167,8 @@ Global
151167
{3B42E8EA-BD33-4324-A771-9A885788D8BA} = {AA9E7227-03DB-4D04-A7FB-E8FD09D4C719}
152168
{74511F4E-FF9D-42C4-9531-A75C61270B73} = {6BFF1AB8-C900-43E5-988F-E07C085BD64A}
153169
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5} = {74511F4E-FF9D-42C4-9531-A75C61270B73}
170+
{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0} = {6BFF1AB8-C900-43E5-988F-E07C085BD64A}
171+
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C} = {256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}
154172
EndGlobalSection
155173
GlobalSection(ExtensibilityGlobals) = postSolution
156174
SolutionGuid = {E418719F-3193-403E-AF58-9BE9F94FD8BE}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
2+
WORKDIR /app
3+
EXPOSE 80
4+
5+
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
6+
WORKDIR /src
7+
8+
COPY "eSchool.sln" "eSchool.sln"
9+
10+
COPY "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj"
11+
12+
COPY "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj"
13+
COPY "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj"
14+
COPY "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj"
15+
COPY "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj"
16+
COPY "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj" "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj"
17+
18+
COPY "src/Libraries/OpenTelemetry/OpenTelemetry.csproj" "src/Libraries/OpenTelemetry/OpenTelemetry.csproj"
19+
20+
COPY "src/Web/WebStatus/WebStatus.csproj" "src/Web/WebStatus/WebStatus.csproj"
21+
22+
COPY "docker-compose.dcproj" "docker-compose.dcproj"
23+
24+
RUN dotnet restore eSchool.sln -nowarn:msb3202,nu1503
25+
26+
COPY . .
27+
WORKDIR /src/src/ApiGateways/eSchool.GraphQL
28+
RUN dotnet build --no-restore -c Release -o /app/build
29+
30+
FROM build as unittest
31+
WORKDIR /src/src/Services/Enrolling/Enrolling.UnitTests
32+
33+
FROM build AS publish
34+
RUN dotnet publish --no-restore -c Release -o /app/publish
35+
36+
FROM base AS final
37+
WORKDIR /app
38+
COPY --from=publish /app/publish .
39+
ENTRYPOINT ["dotnet", "ESchool.GraphQL.dll"]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.Hosting;
7+
using Serilog;
8+
using Serilog.Enrichers.Span;
9+
10+
namespace OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL
11+
{
12+
public class Program
13+
{
14+
public static readonly string Namespace = typeof(Program).Namespace!;
15+
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
16+
17+
public static int Main(string[] args)
18+
{
19+
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
20+
21+
var configuration = GetConfiguration();
22+
23+
Log.Logger = CreateSerilogLogger(configuration);
24+
25+
try
26+
{
27+
Log.Information("Configuring web host ({ApplicationContext})...", AppName);
28+
var host = CreateHostBuilder(configuration, args).Build();
29+
30+
Log.Information("Starting web host ({ApplicationContext})...", AppName);
31+
host.Run();
32+
33+
return 0;
34+
}
35+
catch (Exception ex)
36+
{
37+
Log.Fatal(ex, "Host terminated unexpectedly");
38+
return 1;
39+
}
40+
finally
41+
{
42+
Log.CloseAndFlush();
43+
}
44+
}
45+
46+
public static IHostBuilder CreateHostBuilder(IConfiguration configuration, string[] args) =>
47+
Host.CreateDefaultBuilder(args)
48+
.ConfigureWebHostDefaults(webBuilder =>
49+
{
50+
webBuilder.UseStartup<Startup>();
51+
webBuilder.UseConfiguration(configuration);
52+
webBuilder.UseSerilog();
53+
});
54+
55+
56+
private static ILogger CreateSerilogLogger(IConfiguration configuration)
57+
{
58+
return new LoggerConfiguration()
59+
.MinimumLevel.Verbose()
60+
.Enrich.WithProperty("ApplicationContext", AppName)
61+
.Enrich.FromLogContext()
62+
.Enrich.WithSpan()
63+
.WriteTo.Console()
64+
.WriteTo.Seq("http://seq")
65+
.ReadFrom.Configuration(configuration)
66+
.CreateLogger();
67+
}
68+
69+
private static IConfiguration GetConfiguration()
70+
{
71+
var builder = new ConfigurationBuilder()
72+
.SetBasePath(Directory.GetCurrentDirectory())
73+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
74+
.AddEnvironmentVariables();
75+
76+
// Load other configurations here. Ex. Keyvault or AppConfiguration
77+
return builder.Build();
78+
}
79+
}
80+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using OpenCodeFoundation.OpenTelemetry;
7+
using Serilog;
8+
9+
namespace OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL
10+
{
11+
public class Startup
12+
{
13+
public const string Enrolling = "enrolling";
14+
15+
// This method gets called by the runtime. Use this method to add services to the container.
16+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
17+
public void ConfigureServices(IServiceCollection services)
18+
{
19+
services.AddHttpClient(Enrolling, c =>
20+
c.BaseAddress = new Uri("http://enrolling.api/graphql"));
21+
22+
services
23+
.AddGraphQLServer()
24+
.AddRemoteSchema(Enrolling);
25+
26+
services.AddOpenTelemetryIntegration();
27+
}
28+
29+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
30+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
31+
{
32+
if (env.IsDevelopment())
33+
{
34+
app.UseDeveloperExceptionPage();
35+
}
36+
37+
app.UseSerilogRequestLogging();
38+
39+
app.UseRouting();
40+
41+
app.UseEndpoints(endpoints =>
42+
{
43+
endpoints.MapGraphQL();
44+
});
45+
}
46+
}
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"Serilog": {
3+
"MinimumLevel": {
4+
"Default": "Information",
5+
"Override": {
6+
"Microsoft": "Warning",
7+
"OpenCodeFoundation": "Information",
8+
"System": "Warning"
9+
}
10+
}
11+
},
12+
"AllowedHosts": "*",
13+
"OpenTelemetry": {
14+
"Enabled": true,
15+
"Istio": false,
16+
"Jaeger": {
17+
"Enabled": true,
18+
"ServiceName": "eschool.graphql",
19+
"Host": "jaeger",
20+
"Port": 6831
21+
}
22+
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<AssemblyName>ESchool.GraphQL</AssemblyName>
7+
<RootNamespace>OpenCodeFoundation.ESchool.ApiGateways.ESchool.GraphQL</RootNamespace>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="HotChocolate.AspNetCore" Version="11.0.0" />
13+
<PackageReference Include="HotChocolate.Stitching" Version="11.0.0" />
14+
15+
<!-- Logging -->
16+
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
17+
<PackageReference Include="Serilog.Enrichers.Span" Version="1.0.1" />
18+
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\..\Libraries\OpenTelemetry\OpenTelemetry.csproj" />
23+
</ItemGroup>
24+
25+
</Project>

src/Services/Enrolling/Enrolling.API/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ WORKDIR /src
77

88
COPY "eSchool.sln" "eSchool.sln"
99

10+
COPY "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj"
11+
1012
COPY "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj"
1113
COPY "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj"
1214
COPY "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj"

0 commit comments

Comments
 (0)