From 595e1fb56965ea5cc9caab9500e36e19e3062de7 Mon Sep 17 00:00:00 2001
From: tobias-tengler <45513122+tobias-tengler@users.noreply.github.com>
Date: Mon, 11 Aug 2025 20:46:47 +0200
Subject: [PATCH] Add managed templates
---
 .../.template.config/template.json            | 52 +++++++++++++++++++
 .../HotChocolate.Template.Gateway.csproj      | 21 ++++++++
 templates/gateway-managed/Program.cs          | 50 ++++++++++++++++++
 .../Properties/launchSettings.json            | 14 +++++
 .../appsettings.Development.json              |  8 +++
 templates/gateway-managed/appsettings.json    |  9 ++++
 .../.template.config/template.json            | 52 +++++++++++++++++++
 .../HotChocolate.Template.Server.csproj       | 26 ++++++++++
 templates/server-managed/Program.cs           | 37 +++++++++++++
 .../server-managed/Properties/ModuleInfo.cs   |  1 +
 .../Properties/launchSettings.json            | 14 +++++
 templates/server-managed/Types/Author.cs      |  3 ++
 templates/server-managed/Types/Book.cs        |  3 ++
 templates/server-managed/Types/Query.cs       |  8 +++
 .../appsettings.Development.json              |  8 +++
 templates/server-managed/appsettings.json     |  9 ++++
 16 files changed, 315 insertions(+)
 create mode 100644 templates/gateway-managed/.template.config/template.json
 create mode 100644 templates/gateway-managed/HotChocolate.Template.Gateway.csproj
 create mode 100644 templates/gateway-managed/Program.cs
 create mode 100644 templates/gateway-managed/Properties/launchSettings.json
 create mode 100644 templates/gateway-managed/appsettings.Development.json
 create mode 100644 templates/gateway-managed/appsettings.json
 create mode 100644 templates/server-managed/.template.config/template.json
 create mode 100644 templates/server-managed/HotChocolate.Template.Server.csproj
 create mode 100644 templates/server-managed/Program.cs
 create mode 100644 templates/server-managed/Properties/ModuleInfo.cs
 create mode 100644 templates/server-managed/Properties/launchSettings.json
 create mode 100644 templates/server-managed/Types/Author.cs
 create mode 100644 templates/server-managed/Types/Book.cs
 create mode 100644 templates/server-managed/Types/Query.cs
 create mode 100644 templates/server-managed/appsettings.Development.json
 create mode 100644 templates/server-managed/appsettings.json
diff --git a/templates/gateway-managed/.template.config/template.json b/templates/gateway-managed/.template.config/template.json
new file mode 100644
index 00000000000..6fe2bbf7402
--- /dev/null
+++ b/templates/gateway-managed/.template.config/template.json
@@ -0,0 +1,52 @@
+{
+  "$schema": "http://json.schemastore.org/template",
+  "author": "Michael Staib",
+  "classifications": ["Web", "GraphQL"],
+  "identity": "HotChocolate.Template.ManagedGateway",
+  "sourceName": "HotChocolate.Template.Gateway",
+  "name": "GraphQL Managed Gateway",
+  "shortName": "graphql-managed-gateway",
+  "defaultName": "GraphQL Gateway",
+  "description": "",
+  "preferNameDirectory": true,
+  "tags": {
+    "language": "C#",
+    "type": "project"
+  },
+  "symbols": {
+    "Framework": {
+      "type": "parameter",
+      "description": "The target framework for the project.",
+      "datatype": "choice",
+      "choices": [
+        {
+          "choice": "net8.0",
+          "description": "Target .NET 8"
+        },
+        {
+          "choice": "net9.0",
+          "description": "Target .NET 9"
+        },
+        {
+          "choice": "net10.0",
+          "description": "Target .NET 10"
+        }
+      ],
+      "replaces": "net8.0",
+      "defaultValue": "net8.0"
+    }
+  },
+  "postActions": [
+    {
+      "condition": "(!skipRestore)",
+      "description": "Restore NuGet packages required by this project.",
+      "manualInstructions": [
+        {
+          "text": "Run 'dotnet restore'"
+        }
+      ],
+      "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
+      "continueOnError": true
+    }
+  ]
+}
diff --git a/templates/gateway-managed/HotChocolate.Template.Gateway.csproj b/templates/gateway-managed/HotChocolate.Template.Gateway.csproj
new file mode 100644
index 00000000000..0d6609a4a80
--- /dev/null
+++ b/templates/gateway-managed/HotChocolate.Template.Gateway.csproj
@@ -0,0 +1,21 @@
+
+
+  
+    net9.0
+    enable
+    enable
+  
+
+  
+    
+    
+    
+    
+    
+    
+    
+    
+
+  
+
+
diff --git a/templates/gateway-managed/Program.cs b/templates/gateway-managed/Program.cs
new file mode 100644
index 00000000000..ae5e1af7d5d
--- /dev/null
+++ b/templates/gateway-managed/Program.cs
@@ -0,0 +1,50 @@
+var builder = WebApplication.CreateBuilder(args);
+
+builder.Services
+    .AddHeaderPropagation(c =>
+    {
+        c.Headers.Add("GraphQL-Preflight");
+        c.Headers.Add("Authorization");
+    });
+
+builder.Services
+    .AddHttpClient("fusion")
+    .AddHeaderPropagation();
+
+builder.Services
+    .AddGraphQLGatewayServer()
+    .ConfigureFromCloud(options =>
+    {
+        options.ApiId = "YOUR_API_ID";
+        options.Stage = "prod";
+        options.ApiKey = "YOUR_API_KEY";
+    })
+    // TODO: This needs to go
+    .CoreBuilder.AddInstrumentation();
+
+builder.Services.AddNitroTelemetry(options =>
+{
+    options.ApiId = "YOUR_API_ID";
+    options.Stage = "prod";
+    options.ApiKey = "YOUR_API_KEY";
+});
+
+builder.Services
+    .AddOpenTelemetry()
+    .WithTracing(builder =>
+    {
+        builder.AddHttpClientInstrumentation();
+        builder.AddAspNetCoreInstrumentation();
+        builder.AddNitroExporter();
+    })
+    .WithLogging(builder =>
+    {
+        builder.AddNitroExporter();
+    });
+
+var app = builder.Build();
+
+app.UseHeaderPropagation();
+app.MapGraphQL();
+
+app.Run();
diff --git a/templates/gateway-managed/Properties/launchSettings.json b/templates/gateway-managed/Properties/launchSettings.json
new file mode 100644
index 00000000000..048a6842cb4
--- /dev/null
+++ b/templates/gateway-managed/Properties/launchSettings.json
@@ -0,0 +1,14 @@
+{
+  "profiles": {
+    "http": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "launchBrowser": true,
+      "launchUrl": "http://localhost:5098/graphql",
+      "applicationUrl": "http://localhost:5098",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}
diff --git a/templates/gateway-managed/appsettings.Development.json b/templates/gateway-managed/appsettings.Development.json
new file mode 100644
index 00000000000..0c208ae9181
--- /dev/null
+++ b/templates/gateway-managed/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  }
+}
diff --git a/templates/gateway-managed/appsettings.json b/templates/gateway-managed/appsettings.json
new file mode 100644
index 00000000000..10f68b8c8b4
--- /dev/null
+++ b/templates/gateway-managed/appsettings.json
@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  },
+  "AllowedHosts": "*"
+}
diff --git a/templates/server-managed/.template.config/template.json b/templates/server-managed/.template.config/template.json
new file mode 100644
index 00000000000..115ffb3550e
--- /dev/null
+++ b/templates/server-managed/.template.config/template.json
@@ -0,0 +1,52 @@
+{
+  "$schema": "http://json.schemastore.org/template",
+  "author": "Michael Staib",
+  "classifications": ["Web", "GraphQL"],
+  "identity": "HotChocolate.Template.ManagedServer",
+  "sourceName": "HotChocolate.Template.Server",
+  "name": "GraphQL Managed Server",
+  "shortName": "graphql-managed",
+  "defaultName": "GraphQL",
+  "description": "",
+  "preferNameDirectory": true,
+  "tags": {
+    "language": "C#",
+    "type": "project"
+  },
+  "symbols": {
+    "Framework": {
+      "type": "parameter",
+      "description": "The target framework for the project.",
+      "datatype": "choice",
+      "choices": [
+        {
+          "choice": "net8.0",
+          "description": "Target .NET 8"
+        },
+        {
+          "choice": "net9.0",
+          "description": "Target .NET 9"
+        },
+        {
+          "choice": "net10.0",
+          "description": "Target .NET 10"
+        }
+      ],
+      "replaces": "net8.0",
+      "defaultValue": "net8.0"
+    }
+  },
+  "postActions": [
+    {
+      "condition": "(!skipRestore)",
+      "description": "Restore NuGet packages required by this project.",
+      "manualInstructions": [
+        {
+          "text": "Run 'dotnet restore'"
+        }
+      ],
+      "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
+      "continueOnError": true
+    }
+  ]
+}
diff --git a/templates/server-managed/HotChocolate.Template.Server.csproj b/templates/server-managed/HotChocolate.Template.Server.csproj
new file mode 100644
index 00000000000..a7d8baff835
--- /dev/null
+++ b/templates/server-managed/HotChocolate.Template.Server.csproj
@@ -0,0 +1,26 @@
+
+
+  
+    net8.0
+    enable
+    enable
+    preview
+  
+
+  
+    
+  
+
+  
+    
+    
+    
+    
+      runtime; build; native; contentfiles; analyzers; buildtransitive
+      all
+    
+    
+    
+  
+
+
diff --git a/templates/server-managed/Program.cs b/templates/server-managed/Program.cs
new file mode 100644
index 00000000000..9d5f9c790a5
--- /dev/null
+++ b/templates/server-managed/Program.cs
@@ -0,0 +1,37 @@
+var builder = WebApplication.CreateBuilder(args);
+
+builder.AddGraphQL()
+    .AddTypes()
+    .AddInstrumentation()
+    .AddNitro(options =>
+    {
+        options.ApiId = "YOUR_API_ID";
+        options.Stage = "prod";
+        options.ApiKey = "YOUR_API_KEY";
+    });
+
+builder.Services
+    .AddNitroTelemetry(options =>
+    {
+        options.ApiId = "YOUR_API_ID";
+        options.Stage = "prod";
+        options.ApiKey = "YOUR_API_KEY";
+    });
+
+builder.Services
+    .AddOpenTelemetry()
+    .WithTracing(builder =>
+    {
+        builder.AddAspNetCoreInstrumentation();
+        builder.AddNitroExporter();
+    })
+    .WithLogging(builder =>
+    {
+        builder.AddNitroExporter();
+    });
+
+var app = builder.Build();
+
+app.MapGraphQL();
+
+app.RunWithGraphQLCommands(args);
diff --git a/templates/server-managed/Properties/ModuleInfo.cs b/templates/server-managed/Properties/ModuleInfo.cs
new file mode 100644
index 00000000000..077f90a3f14
--- /dev/null
+++ b/templates/server-managed/Properties/ModuleInfo.cs
@@ -0,0 +1 @@
+[assembly: Module("Types")]
diff --git a/templates/server-managed/Properties/launchSettings.json b/templates/server-managed/Properties/launchSettings.json
new file mode 100644
index 00000000000..46555420fdd
--- /dev/null
+++ b/templates/server-managed/Properties/launchSettings.json
@@ -0,0 +1,14 @@
+{
+  "profiles": {
+    "http": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "launchBrowser": true,
+      "launchUrl": "http://localhost:5095/graphql",
+      "applicationUrl": "http://localhost:5095",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}
diff --git a/templates/server-managed/Types/Author.cs b/templates/server-managed/Types/Author.cs
new file mode 100644
index 00000000000..b1382f8ea8d
--- /dev/null
+++ b/templates/server-managed/Types/Author.cs
@@ -0,0 +1,3 @@
+namespace HotChocolate.Template.Server.Types;
+
+public record Author(string Name);
diff --git a/templates/server-managed/Types/Book.cs b/templates/server-managed/Types/Book.cs
new file mode 100644
index 00000000000..3fe1607cdb7
--- /dev/null
+++ b/templates/server-managed/Types/Book.cs
@@ -0,0 +1,3 @@
+namespace HotChocolate.Template.Server.Types;
+
+public record Book(string Title, Author Author);
diff --git a/templates/server-managed/Types/Query.cs b/templates/server-managed/Types/Query.cs
new file mode 100644
index 00000000000..845c1721368
--- /dev/null
+++ b/templates/server-managed/Types/Query.cs
@@ -0,0 +1,8 @@
+namespace HotChocolate.Template.Server.Types;
+
+[QueryType]
+public static class Query
+{
+    public static Book GetBook()
+        => new Book("C# in depth.", new Author("Jon Skeet"));
+}
diff --git a/templates/server-managed/appsettings.Development.json b/templates/server-managed/appsettings.Development.json
new file mode 100644
index 00000000000..0c208ae9181
--- /dev/null
+++ b/templates/server-managed/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  }
+}
diff --git a/templates/server-managed/appsettings.json b/templates/server-managed/appsettings.json
new file mode 100644
index 00000000000..10f68b8c8b4
--- /dev/null
+++ b/templates/server-managed/appsettings.json
@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  },
+  "AllowedHosts": "*"
+}