From ca1f461df100439e308ced5f34736e8c03180732 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sun, 8 Sep 2024 21:08:50 -0400 Subject: [PATCH] Allow GraphQL to be worked on in `dev` by hiding it behind an internal parameter --- .github/workflows/ci-pipeline.yml | 1 + .../Configuration/InternalConfiguration.cs | 10 +++++++++ src/Tgstation.Server.Host/Core/Application.cs | 22 +++++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index def3136a44..e0e8354c1b 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -40,6 +40,7 @@ env: TGS_WEBPANEL_NODE_VERSION: 20.x TGS_TEST_GITHUB_TOKEN: ${{ secrets.LIVE_TESTS_TOKEN }} PACKAGING_PRIVATE_KEY_PASSPHRASE: ${{ secrets.PACKAGING_PRIVATE_KEY_PASSPHRASE }} + Internal__EnableGraphQL: true concurrency: group: "ci-${{ (github.event_name != 'push' && github.event_name != 'schedule' && github.event.inputs.pull_request_number) || github.run_id }}-${{ github.event_name }}" diff --git a/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs b/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs index 009c766cd8..611c9c9fdf 100644 --- a/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs @@ -35,6 +35,16 @@ /// public string? DumpGraphQLApiPath { get; set; } + /// + /// Enables hosting the experimental GraphQL API in Release builds. + /// + public bool EnableGraphQL +#if DEBUG + => true; +#else + { get; set; } +#endif + /// /// The base path for the app settings configuration files. /// diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index cfdd54f969..fa3c35dbbf 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -288,12 +288,13 @@ namespace Tgstation.Server.Host.Core services.AddSingleton(); // configure graphql - services - .AddGraphQLServer() - .AddAuthorization() - .AddType() - .BindRuntimeType() - .AddQueryType(); + if (postSetupServices.InternalConfiguration.EnableGraphQL) + services + .AddGraphQLServer() + .AddAuthorization() + .AddType() + .BindRuntimeType() + .AddQueryType(); void AddTypedContext() where TContext : DatabaseContext @@ -466,6 +467,7 @@ namespace Tgstation.Server.Host.Core /// The containing the to use. /// The containing the to use. /// The containing the to use. + /// The containing the to use. /// The for the . public void Configure( IApplicationBuilder applicationBuilder, @@ -476,6 +478,7 @@ namespace Tgstation.Server.Host.Core IOptions controlPanelConfigurationOptions, IOptions generalConfigurationOptions, IOptions swarmConfigurationOptions, + IOptions internalConfigurationOptions, ILogger logger) { ArgumentNullException.ThrowIfNull(applicationBuilder); @@ -489,6 +492,7 @@ namespace Tgstation.Server.Host.Core var controlPanelConfiguration = controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions)); var generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); var swarmConfiguration = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions)); + var internalConfiguration = internalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(internalConfigurationOptions)); ArgumentNullException.ThrowIfNull(logger); @@ -609,7 +613,11 @@ namespace Tgstation.Server.Host.Core // majority of handling is done in the controllers endpoints.MapControllers(); - endpoints.MapGraphQL(Routes.GraphQL); + if (internalConfiguration.EnableGraphQL) + { + logger.LogWarning("Enabling GraphQL. This API is experimental and breaking changes may occur at any time!"); + endpoints.MapGraphQL(Routes.GraphQL); + } }); // 404 anything that gets this far