diff --git a/Server.Tests/Server.Tests.csproj b/Server.Tests/Server.Tests.csproj index 8a821d3..e9480ce 100644 --- a/Server.Tests/Server.Tests.csproj +++ b/Server.Tests/Server.Tests.csproj @@ -1,26 +1,21 @@ - - net7.0 + net8.0 enable enable false - - - - + - \ No newline at end of file diff --git a/Server.Tests/SubgraphTest.cs b/Server.Tests/SubgraphTest.cs index 262265f..e2561e3 100644 --- a/Server.Tests/SubgraphTest.cs +++ b/Server.Tests/SubgraphTest.cs @@ -1,4 +1,3 @@ -using ApolloGraphQL.HotChocolate.Federation.Two; using HotChocolate; using HotChocolate.Execution; using Snapshooter.Xunit; @@ -11,10 +10,7 @@ private static async Task CreateSchemaAsync() => await new ServiceCollection() .AddSingleton() .AddGraphQL() - .AddApolloFederationV2(new CustomSchema()) - .AddType() - .AddQueryType() - .RegisterService() + .AddGraphQLServices() .BuildRequestExecutorAsync(); [Fact] diff --git a/Server.Tests/__snapshots__/EntitiesResolverTests.Foo_By_Id.snap b/Server.Tests/__snapshots__/EntitiesResolverTests.Foo_By_Id.snap deleted file mode 100644 index 1f0216f..0000000 --- a/Server.Tests/__snapshots__/EntitiesResolverTests.Foo_By_Id.snap +++ /dev/null @@ -1,8 +0,0 @@ -{ - "data": { - "thing": { - "id": "1", - "name": "Name" - } - } -} diff --git a/Server.Tests/__snapshots__/EntitiesResolverTests.Schema_Snapshot.snap b/Server.Tests/__snapshots__/EntitiesResolverTests.Schema_Snapshot.snap index 28cf566..c927fba 100644 --- a/Server.Tests/__snapshots__/EntitiesResolverTests.Schema_Snapshot.snap +++ b/Server.Tests/__snapshots__/EntitiesResolverTests.Schema_Snapshot.snap @@ -1,5 +1,10 @@ -schema @contact(name: "Thing Server Team", url: "https:\/\/myteam.slack.com\/archives\/teams-chat-room-url", description: "send urgent issues to [#oncall](https:\/\/yourteam.slack.com\/archives\/oncall)") @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.5", import: [ "@extends", "@external", "@key", "@inaccessible", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet", "@composeDirective", "@interfaceObject" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.5", import: [ "@extends", "@external", "@key", "@inaccessible", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet", "@composeDirective", "@interfaceObject" ]) @contact(name: "Thing Server Team", url: "https:\/\/myteam.slack.com\/archives\/teams-chat-room-url", description: "send urgent issues to [#oncall](https:\/\/yourteam.slack.com\/archives\/oncall)") { query: Query + mutation: Mutation +} + +type Mutation { + createThing(thing: ThingInput!): Thing } type Query { @@ -21,6 +26,11 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Thing +input ThingInput { + id: String! + name: String +} + "Indicates to composition that the target element is accessible only to the authenticated supergraph users." directive @authenticated on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM diff --git a/Server.sln b/Server.sln index 92252b6..5590d6a 100644 --- a/Server.sln +++ b/Server.sln @@ -1,36 +1,36 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{2FE5A0A3-9A07-42E0-B6D3-486E17167C2D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{6DC201A7-45E1-4223-8E6B-779E6520859E}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server.Tests", "Server.Tests", "{BE4BAB9F-3D26-4D64-AB1C-F37EDEBF5545}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Tests", "Server.Tests\Server.Tests.csproj", "{AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6DC201A7-45E1-4223-8E6B-779E6520859E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6DC201A7-45E1-4223-8E6B-779E6520859E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6DC201A7-45E1-4223-8E6B-779E6520859E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6DC201A7-45E1-4223-8E6B-779E6520859E}.Release|Any CPU.Build.0 = Release|Any CPU - {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {6DC201A7-45E1-4223-8E6B-779E6520859E} = {2FE5A0A3-9A07-42E0-B6D3-486E17167C2D} - {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8} = {BE4BAB9F-3D26-4D64-AB1C-F37EDEBF5545} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{2FE5A0A3-9A07-42E0-B6D3-486E17167C2D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{6DC201A7-45E1-4223-8E6B-779E6520859E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server.Tests", "Server.Tests", "{BE4BAB9F-3D26-4D64-AB1C-F37EDEBF5545}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server.Tests", "Server.Tests\Server.Tests.csproj", "{AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6DC201A7-45E1-4223-8E6B-779E6520859E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DC201A7-45E1-4223-8E6B-779E6520859E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DC201A7-45E1-4223-8E6B-779E6520859E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DC201A7-45E1-4223-8E6B-779E6520859E}.Release|Any CPU.Build.0 = Release|Any CPU + {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {6DC201A7-45E1-4223-8E6B-779E6520859E} = {2FE5A0A3-9A07-42E0-B6D3-486E17167C2D} + {AFD5A3E8-9B16-452E-A11D-A688CAA9D8E8} = {BE4BAB9F-3D26-4D64-AB1C-F37EDEBF5545} + EndGlobalSection +EndGlobal diff --git a/Server/Extensions/GraphServiceCollectionExtensions.cs b/Server/Extensions/GraphServiceCollectionExtensions.cs new file mode 100644 index 0000000..40c3b55 --- /dev/null +++ b/Server/Extensions/GraphServiceCollectionExtensions.cs @@ -0,0 +1,23 @@ +using ApolloGraphQL.HotChocolate.Federation.Two; +using HotChocolate.Execution.Configuration; + +namespace Microsoft.Extensions.DependencyInjection; + +public static class GraphServiceCollectionExtensions +{ + public static IRequestExecutorBuilder AddGraphQLServices(this IRequestExecutorBuilder builder) + { + return builder + .AddApolloFederationV2(schemaConfiguration: schema => + { + schema.Contact( + name: "Thing Server Team", + url: "https://myteam.slack.com/archives/teams-chat-room-url", + description: "send urgent issues to [#oncall](https://yourteam.slack.com/archives/oncall)"); + }) + .AddType() + .AddQueryType() + .AddMutationType() + .RegisterService(); + } +} \ No newline at end of file diff --git a/Server/Program.cs b/Server/Program.cs index 8f38770..2479afd 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,34 +1,21 @@ -using ApolloGraphQL.HotChocolate.Federation.Two; using HotChocolate.AspNetCore; using HotChocolate.Execution; -var builder = WebApplication.CreateBuilder(args); +var builder = WebApplication.CreateSlimBuilder(args); builder.Services .AddSingleton(); builder.Services .AddGraphQLServer() - .AddApolloFederationV2(new CustomSchema()) - .AddType() - .AddQueryType() - .AddMutationType() - .RegisterService() + .AddGraphQLServices() .AddHttpRequestInterceptor(); -var port = Environment.GetEnvironmentVariable("PORT") ?? "4001"; -builder.WebHost.UseUrls($"http://*:{port}"); - var app = builder.Build(); app.MapGraphQL(); -var bananaCakePop = app.MapBananaCakePop("/"); -bananaCakePop.WithOptions(new GraphQLToolOptions { GraphQLEndpoint = "/graphql" }); -if (args.Length > 1 && args[0] == "schema" && args[1] == "export") - _ = app.RunWithGraphQLCommandsAsync(args); -else - app.Run(); +app.RunWithGraphQLCommands(args); public sealed class RouterAuthInterceptor : DefaultHttpRequestInterceptor { diff --git a/Server/Properties/launchSettings.json b/Server/Properties/launchSettings.json new file mode 100644 index 0000000..eb46e5f --- /dev/null +++ b/Server/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49905", + "sslPort": 44344 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "graphql", + "applicationUrl": "http://localhost:5239", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "graphql", + "applicationUrl": "https://localhost:7037;http://localhost:5239", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "graphql", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Server/Server.csproj b/Server/Server.csproj index 62aebab..09e0d99 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -1,19 +1,16 @@ - - net7.0 + net8.0 enable enable + true - - - \ No newline at end of file diff --git a/Server/Types/CustomSchema.cs b/Server/Types/CustomSchema.cs deleted file mode 100644 index 6c8b062..0000000 --- a/Server/Types/CustomSchema.cs +++ /dev/null @@ -1,10 +0,0 @@ -using ApolloGraphQL.HotChocolate.Federation; -using ApolloGraphQL.HotChocolate.Federation.Two; - -namespace Server; - -[Contact(name: "Thing Server Team", url: "https://myteam.slack.com/archives/teams-chat-room-url", description: "send urgent issues to [#oncall](https://yourteam.slack.com/archives/oncall)")] -public class CustomSchema : FederatedSchema -{ - -} \ No newline at end of file