From ffa51cfce441894c3f7e8b7b0772812b28c3398e Mon Sep 17 00:00:00 2001 From: gamer147 Date: Sat, 22 Nov 2025 00:33:06 -0500 Subject: [PATCH] [FA-13] Adds Fusion gateway, need to setup a local build and stitch process. Only NovelService included right now. --- .../Controllers/TestController.cs | 75 ------------------- FictionArchive.API/FictionArchive.API.csproj | 6 +- FictionArchive.API/Program.cs | 38 ++++------ .../Properties/launchSettings.json | 2 +- ...FictionArchive.Service.NovelService.csproj | 1 + .../Program.cs | 2 + .../subgraph-config.json | 6 ++ .../Extensions/GraphQLExtensions.cs | 26 ++++--- FictionArchive.sln | 5 -- 9 files changed, 45 insertions(+), 116 deletions(-) delete mode 100644 FictionArchive.API/Controllers/TestController.cs create mode 100644 FictionArchive.Service.NovelService/subgraph-config.json diff --git a/FictionArchive.API/Controllers/TestController.cs b/FictionArchive.API/Controllers/TestController.cs deleted file mode 100644 index c6efa45..0000000 --- a/FictionArchive.API/Controllers/TestController.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace FictionArchive.API.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class TestController : ControllerBase - { - /*private readonly FictionArchiveDbContext _dbContext; - private readonly ISourceAdapter _novelpiaAdapter; - private readonly ITranslationEngineAdapter _translationEngine; - - public TestController(ISourceAdapter novelpiaAdapter, FictionArchiveDbContext dbContext, ITranslationEngineAdapter translationEngine) - { - _novelpiaAdapter = novelpiaAdapter; - _dbContext = dbContext; - _translationEngine = translationEngine; - } - - [HttpGet("GetNovel")] - public async Task GetNovel(string novelUrl) - { - var novel = await _novelpiaAdapter.GetMetadata(novelUrl); - novel.Source = new Source() - { - Name = "Novelpia", - Id = 1, - Url = "https://novelpia.com" - }; - _dbContext.Novels.Add(novel); - await _dbContext.SaveChangesAsync(); - return novel; - } - - [HttpGet("GetChapter")] - public async Task GetChapter(uint novelId, uint chapterNumber) - { - var novel = await _dbContext.Novels.Include(n => n.Chapters).ThenInclude(c => c.Translations).FirstOrDefaultAsync(n => n.Id == novelId); - var chapter = novel.Chapters.FirstOrDefault(c => c.Order == chapterNumber); - var rawChapter = await _novelpiaAdapter.GetRawChapter(chapter.Url); - chapter.Translations.Add(new ChapterTranslation() - { - Language = novel.RawLanguage, - Body = rawChapter - }); - await _dbContext.SaveChangesAsync(); - return rawChapter; - } - - [HttpPost("TranslateChapter")] - public async Task TranslateChapter(uint novelId, uint chapterNumber, Language to) - { - var novel = await _dbContext.Novels.Include(n => n.Chapters) - .ThenInclude(c => c.Translations).FirstOrDefaultAsync(novel => novel.Id == novelId); - var chapter = novel.Chapters.FirstOrDefault(c => c.Order == chapterNumber); - var chapterRaw = chapter.Translations.FirstOrDefault(ct => ct.Language == novel.RawLanguage); - var newTranslation = new ChapterTranslation() - { - Language = to, - TranslationEngine = new TranslationEngine() - { - Name = "DeepL" - } - }; - var translation = await _translationEngine.GetTranslation(chapterRaw.Body, novel.RawLanguage, to); - newTranslation.Body = translation; - chapter.Translations.Add(newTranslation); - await _dbContext.SaveChangesAsync(); - - return newTranslation; - }*/ - } -} diff --git a/FictionArchive.API/FictionArchive.API.csproj b/FictionArchive.API/FictionArchive.API.csproj index aafc33d..4246f74 100644 --- a/FictionArchive.API/FictionArchive.API.csproj +++ b/FictionArchive.API/FictionArchive.API.csproj @@ -11,6 +11,7 @@ + all @@ -28,8 +29,11 @@ - + + + + diff --git a/FictionArchive.API/Program.cs b/FictionArchive.API/Program.cs index cdf2123..4a95395 100644 --- a/FictionArchive.API/Program.cs +++ b/FictionArchive.API/Program.cs @@ -1,3 +1,5 @@ +using FictionArchive.Service.Shared.Extensions; + namespace FictionArchive.API; public class Program @@ -6,38 +8,26 @@ public class Program { var builder = WebApplication.CreateBuilder(args); - // Add services to the container. - - // OpenAPI & REST - builder.Services.AddControllers(); - // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle - builder.Services.AddEndpointsApiExplorer(); - builder.Services.AddSwaggerGen(); - - builder.Services.AddMemoryCache(); - builder.Services.AddHealthChecks(); + + #region Fusion Gateway + + builder.Services.AddHttpClient("Fusion"); + + builder.Services + .AddFusionGatewayServer() + .ConfigureFromFile("gateway.fgp") + .CoreBuilder.ApplySaneDefaults(); + + #endregion var app = builder.Build(); - // Configure the HTTP request pipeline. - if (app.Environment.IsDevelopment()) - { - app.UseSwagger(); - app.UseSwaggerUI(); - } - app.UseHttpsRedirection(); - - app.UseAuthentication(); - - app.UseAuthorization(); - - app.MapGraphQL(); app.MapHealthChecks("/healthz"); - app.MapControllers(); + app.MapGraphQL(); app.Run(); } diff --git a/FictionArchive.API/Properties/launchSettings.json b/FictionArchive.API/Properties/launchSettings.json index dddb254..651e411 100644 --- a/FictionArchive.API/Properties/launchSettings.json +++ b/FictionArchive.API/Properties/launchSettings.json @@ -23,7 +23,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "graphql", "applicationUrl": "https://localhost:7063;http://localhost:5234", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/FictionArchive.Service.NovelService/FictionArchive.Service.NovelService.csproj b/FictionArchive.Service.NovelService/FictionArchive.Service.NovelService.csproj index 2d82c93..ac56df2 100644 --- a/FictionArchive.Service.NovelService/FictionArchive.Service.NovelService.csproj +++ b/FictionArchive.Service.NovelService/FictionArchive.Service.NovelService.csproj @@ -8,6 +8,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/FictionArchive.Service.NovelService/Program.cs b/FictionArchive.Service.NovelService/Program.cs index 79fa235..5592c15 100644 --- a/FictionArchive.Service.NovelService/Program.cs +++ b/FictionArchive.Service.NovelService/Program.cs @@ -76,6 +76,8 @@ public class Program app.MapHealthChecks("/healthz"); app.MapGraphQL(); + + app.RunWithGraphQLCommands(args); app.Run(); } diff --git a/FictionArchive.Service.NovelService/subgraph-config.json b/FictionArchive.Service.NovelService/subgraph-config.json new file mode 100644 index 0000000..0d9b586 --- /dev/null +++ b/FictionArchive.Service.NovelService/subgraph-config.json @@ -0,0 +1,6 @@ +{ + "subgraph": "Novels", + "http": { + "baseAddress": "http://localhost:5101/graphql" + } +} \ No newline at end of file diff --git a/FictionArchive.Service.Shared/Extensions/GraphQLExtensions.cs b/FictionArchive.Service.Shared/Extensions/GraphQLExtensions.cs index b51551a..d329975 100644 --- a/FictionArchive.Service.Shared/Extensions/GraphQLExtensions.cs +++ b/FictionArchive.Service.Shared/Extensions/GraphQLExtensions.cs @@ -10,15 +10,21 @@ public static class GraphQLExtensions public static IRequestExecutorBuilder AddDefaultGraphQl(this IServiceCollection services) where TQuery : class where TMutation : class { return services.AddGraphQLServer() - .AddQueryType() - .AddMutationType() - .AddDiagnosticEventListener() - .AddErrorFilter() - .AddType() - .AddType() - .AddMutationConventions(applyToAllMutations: true) - .AddFiltering(opt => opt.AddDefaults().BindRuntimeType()) - .AddSorting() - .AddProjections(); + .AddQueryType() + .AddMutationType() + .ApplySaneDefaults(); + + } + + public static IRequestExecutorBuilder ApplySaneDefaults(this IRequestExecutorBuilder builder) + { + return builder.AddDiagnosticEventListener() + .AddErrorFilter() + .AddType() + .AddType() + .AddMutationConventions(applyToAllMutations: true) + .AddFiltering(opt => opt.AddDefaults().BindRuntimeType()) + .AddSorting() + .AddProjections(); } } \ No newline at end of file diff --git a/FictionArchive.sln b/FictionArchive.sln index e999c3b..cee3dc2 100644 --- a/FictionArchive.sln +++ b/FictionArchive.sln @@ -16,11 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.User EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.AuthenticationService", "FictionArchive.Service.AuthenticationService\FictionArchive.Service.AuthenticationService.csproj", "{70C4AE82-B01E-421D-B590-C0F47E63CD0C}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{35C67E32-A17F-4EAB-B141-88AFCE11FF9C}" - ProjectSection(SolutionItems) = preProject - compose.yaml = compose.yaml - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU