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

Commit

Permalink
feat: add graphql api gateway (#240)
Browse files Browse the repository at this point in the history
* graphql gateway implementation

* update readme
  • Loading branch information
ratanparai committed Nov 25, 2020
1 parent 16abcfe commit dc0e813
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 4 deletions.
16 changes: 12 additions & 4 deletions README.md
Expand Up @@ -36,25 +36,32 @@ $ docker-compose up
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/)

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

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

## Tech & Tools

- .NET Core
- Docker
- Orchestrators: Kubernetes
- Visual Studio
- MongoDB
- SQL Server
- Azure DevOps
- Redis
- RabbitMQ
- API Gateway
- GraphQL

## Contributing

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.

## Sending feedback and pull requests

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

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

## License

Code licensed under the [MIT License](https://github.com/OpenCodeFoundation/eSchool/blob/master/LICENSE).
7 changes: 7 additions & 0 deletions docker-compose.override.yml
Expand Up @@ -33,6 +33,13 @@ services:
ports:
- "5107:80"

eschool.graphql:
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://0.0.0.0:80
ports:
- "5101:80"

jaeger:
environment:
- COLLECTOR_ZIPKIN_HTTP_PORT=9411
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Expand Up @@ -21,5 +21,11 @@ services:
context: .
dockerfile: src/Web/WebStatus/Dockerfile

eschool.graphql:
image: ${REGISTRY:-eschool}/eschool.graphql:${TAG:-latest}
build:
context: .
dockerfile: src/ApiGateways/eSchool.GraphQL/Dockerfile

jaeger:
image: jaegertracing/all-in-one
18 changes: 18 additions & 0 deletions eSchool.sln
Expand Up @@ -29,6 +29,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateways", "ApiGateways", "{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -135,6 +139,18 @@ Global
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}.Release|x64.Build.0 = Release|Any CPU
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}.Release|x86.ActiveCfg = Release|Any CPU
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}.Release|x86.Build.0 = Release|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x64.Build.0 = Debug|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x86.ActiveCfg = Debug|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Debug|x86.Build.0 = Debug|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|Any CPU.Build.0 = Release|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x64.ActiveCfg = Release|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x64.Build.0 = Release|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x86.ActiveCfg = Release|Any CPU
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -151,6 +167,8 @@ Global
{3B42E8EA-BD33-4324-A771-9A885788D8BA} = {AA9E7227-03DB-4D04-A7FB-E8FD09D4C719}
{74511F4E-FF9D-42C4-9531-A75C61270B73} = {6BFF1AB8-C900-43E5-988F-E07C085BD64A}
{7B410F3B-36E0-4853-9B4E-41D0CC2865B5} = {74511F4E-FF9D-42C4-9531-A75C61270B73}
{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0} = {6BFF1AB8-C900-43E5-988F-E07C085BD64A}
{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C} = {256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E418719F-3193-403E-AF58-9BE9F94FD8BE}
Expand Down
39 changes: 39 additions & 0 deletions src/ApiGateways/eSchool.GraphQL/Dockerfile
@@ -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"]
80 changes: 80 additions & 0 deletions src/ApiGateways/eSchool.GraphQL/Program.cs
@@ -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();
}
}
}
47 changes: 47 additions & 0 deletions src/ApiGateways/eSchool.GraphQL/Startup.cs
@@ -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();
});
}
}
}
23 changes: 23 additions & 0 deletions src/ApiGateways/eSchool.GraphQL/appsettings.json
@@ -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
}
}
}
25 changes: 25 additions & 0 deletions src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj
@@ -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>
2 changes: 2 additions & 0 deletions src/Services/Enrolling/Enrolling.API/Dockerfile
Expand Up @@ -7,6 +7,8 @@ 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"
Expand Down
1 change: 1 addition & 0 deletions src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.2.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.1.2" />
<PackageReference Include="HotChocolate.AspNetCore" Version="11.0.0" />
<PackageReference Include="HotChocolate.Stitching" Version="11.0.0" />

<!-- In-memory commandbus -->
<PackageReference Include="MediatR" Version="9.0.0" />
Expand Down
2 changes: 2 additions & 0 deletions src/Web/WebStatus/Dockerfile
Expand Up @@ -7,6 +7,8 @@ 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"
Expand Down

0 comments on commit dc0e813

Please sign in to comment.