From a72a88b611fce7fe9297eca65c6043a2c1c66734 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Mon, 25 Dec 2023 13:30:44 +0200 Subject: [PATCH 1/7] Remove code duplication --- .../Fusion/test/Shared/DemoSubgraph.cs | 84 ++++++------------- 1 file changed, 27 insertions(+), 57 deletions(-) diff --git a/src/HotChocolate/Fusion/test/Shared/DemoSubgraph.cs b/src/HotChocolate/Fusion/test/Shared/DemoSubgraph.cs index 0f3461aa8cc..40abd7bd504 100644 --- a/src/HotChocolate/Fusion/test/Shared/DemoSubgraph.cs +++ b/src/HotChocolate/Fusion/test/Shared/DemoSubgraph.cs @@ -40,64 +40,34 @@ public DemoSubgraph( public TestServer Server { get; } public SubgraphConfiguration ToConfiguration( - string extensions, + string? extensions = null, + JsonElement? configurationExtensions = null, bool onlyHttp = false) - => onlyHttp - ? new SubgraphConfiguration( - Name, - Schema.ToString(_serializerOptions), - Utf8GraphQLParser.Parse(extensions).ToString(_serializerOptions), - new IClientConfiguration[] { new HttpClientConfiguration(HttpEndpointUri) }, - null) - : new SubgraphConfiguration( - Name, - Schema.ToString(_serializerOptions), - Utf8GraphQLParser.Parse(extensions).ToString(_serializerOptions), - new IClientConfiguration[] - { - new HttpClientConfiguration(HttpEndpointUri), - new WebSocketClientConfiguration(WebSocketEndpointUri), - }, - null); + { + IClientConfiguration[] configs; + { + int configCount = 1; + if (!onlyHttp) + { + configCount++; + } + configs = new IClientConfiguration[configCount]; + configs[0] = new HttpClientConfiguration(HttpEndpointUri); + if (!onlyHttp) + { + configs[1] = new WebSocketClientConfiguration(WebSocketEndpointUri); + } + } - public SubgraphConfiguration ToConfiguration( - string extensions, - JsonElement configurationExtensions, - bool onlyHttp = false) - => onlyHttp - ? new SubgraphConfiguration( - Name, - Schema.ToString(_serializerOptions), - Utf8GraphQLParser.Parse(extensions).ToString(_serializerOptions), - new IClientConfiguration[] { new HttpClientConfiguration(HttpEndpointUri) }, - configurationExtensions) - : new SubgraphConfiguration( - Name, - Schema.ToString(_serializerOptions), - Utf8GraphQLParser.Parse(extensions).ToString(_serializerOptions), - new IClientConfiguration[] - { - new HttpClientConfiguration(HttpEndpointUri), - new WebSocketClientConfiguration(WebSocketEndpointUri), - }, - configurationExtensions); + var extensionsList = extensions is null + ? Array.Empty() + : [ Utf8GraphQLParser.Parse(extensions).ToString(_serializerOptions) ]; - public SubgraphConfiguration ToConfiguration(bool onlyHttp = false) - => onlyHttp - ? new SubgraphConfiguration( - Name, - Schema.ToString(_serializerOptions), - Array.Empty(), - new IClientConfiguration[] { new HttpClientConfiguration(HttpEndpointUri) }, - null) - : new SubgraphConfiguration( - Name, - Schema.ToString(_serializerOptions), - Array.Empty(), - new IClientConfiguration[] - { - new HttpClientConfiguration(HttpEndpointUri), - new WebSocketClientConfiguration(WebSocketEndpointUri), - }, - null); + return new SubgraphConfiguration( + Name, + Schema.ToString(_serializerOptions), + extensionsList, + configs, + configurationExtensions); + } } From 0f2cb1e71fd17fd25814b8c249ecc229733725d8 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Mon, 25 Dec 2023 13:57:58 +0200 Subject: [PATCH 2/7] Refactor demo project initialization --- .../Fusion/test/Shared/DemoProject.cs | 387 +++++------------- .../Fusion/test/Shared/ErrorCompositionLog.cs | 4 +- 2 files changed, 110 insertions(+), 281 deletions(-) diff --git a/src/HotChocolate/Fusion/test/Shared/DemoProject.cs b/src/HotChocolate/Fusion/test/Shared/DemoProject.cs index 551f83f32b1..93065121447 100644 --- a/src/HotChocolate/Fusion/test/Shared/DemoProject.cs +++ b/src/HotChocolate/Fusion/test/Shared/DemoProject.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using HotChocolate.AspNetCore.Tests.Utilities; using HotChocolate.Fusion.Clients; using HotChocolate.Fusion.Shared.Accounts; @@ -12,65 +13,87 @@ using HotChocolate.Types.Descriptors; using HotChocolate.Utilities.Introspection; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using static HotChocolate.WellKnownContextData; namespace HotChocolate.Fusion.Shared; +internal enum DemoProjectType +{ + Accounts, + Reviews, + Reviews2, + Products, + Shipping, + Appointment, + Patient1, + Books, + Authors, + Count, +} + +internal readonly struct DemoProjectValues +{ + public required T[] All { get; init; } + + public static DemoProjectValues Create() + { + var all = new T[(int)DemoProjectType.Count]; + return new DemoProjectValues + { + All = all, + }; + } + + public ref T this[DemoProjectType type] + { + get => ref All[(int)type]; + } + + public bool AllSet => All.All(x => x != null); + + public ref T Accounts => ref All[(int)DemoProjectType.Accounts]; + public ref T Reviews => ref All[(int)DemoProjectType.Reviews]; + public ref T Reviews2 => ref All[(int)DemoProjectType.Reviews2]; + public ref T Products => ref All[(int)DemoProjectType.Products]; + public ref T Shipping => ref All[(int)DemoProjectType.Shipping]; + public ref T Appointment => ref All[(int)DemoProjectType.Appointment]; + public ref T Patient1 => ref All[(int)DemoProjectType.Patient1]; + public ref T Books => ref All[(int)DemoProjectType.Books]; + public ref T Authors => ref All[(int)DemoProjectType.Authors]; +} + public sealed class DemoProject : IDisposable { - private readonly IReadOnlyList _disposables; + private readonly List _disposables; private bool _disposed; + private readonly DemoProjectValues _subgraphs; private DemoProject( - IReadOnlyList disposables, - DemoSubgraph accounts, - DemoSubgraph reviews, - DemoSubgraph reviews2, - DemoSubgraph products, - DemoSubgraph shipping, - DemoSubgraph appointment, - DemoSubgraph patient1, - DemoSubgraph books, - DemoSubgraph authors, + List disposables, + DemoProjectValues subgraphs, IHttpClientFactory clientFactory, IWebSocketConnectionFactory webSocketConnectionFactory) { + _subgraphs = subgraphs; _disposables = disposables; - Accounts = accounts; - Reviews = reviews; - Reviews2 = reviews2; - Products = products; - Shipping = shipping; - Appointment = appointment; - Patient1 = patient1; - Books = books; - Authors = authors; HttpClientFactory = clientFactory; WebSocketConnectionFactory = webSocketConnectionFactory; } public IHttpClientFactory HttpClientFactory { get; } - public IWebSocketConnectionFactory WebSocketConnectionFactory { get; } - public DemoSubgraph Reviews { get; } - - public DemoSubgraph Reviews2 { get; } - - public DemoSubgraph Products { get; } - - public DemoSubgraph Accounts { get; } - - public DemoSubgraph Shipping { get; } - - public DemoSubgraph Appointment { get; } - - public DemoSubgraph Patient1 { get; } - - public DemoSubgraph Books { get; } - - public DemoSubgraph Authors { get; } + public DemoSubgraph Reviews => _subgraphs.Reviews; + public DemoSubgraph Reviews2 => _subgraphs.Reviews2; + public DemoSubgraph Products => _subgraphs.Products; + public DemoSubgraph Accounts => _subgraphs.Accounts; + public DemoSubgraph Shipping => _subgraphs.Shipping; + public DemoSubgraph Appointment => _subgraphs.Appointment; + public DemoSubgraph Patient1 => _subgraphs.Patient1; + public DemoSubgraph Books => _subgraphs.Books; + public DemoSubgraph Authors => _subgraphs.Authors; public static async Task CreateAsync(CancellationToken ct = default) { @@ -78,7 +101,8 @@ public static async Task CreateAsync(CancellationToken ct = default TestServerFactory testServerFactory = new(); disposables.Add(testServerFactory); - var reviews = testServerFactory.Create( + var testServers = DemoProjectValues.Create(); + testServers.Reviews = testServerFactory.Create( s => s .AddRouting() .AddSingleton() @@ -93,15 +117,8 @@ public static async Task CreateAsync(CancellationToken ct = default .UseWebSockets() .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(reviews); - - var reviewsClient = reviews.CreateClient(); - reviewsClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var reviewsSchema = await IntrospectionClient - .IntrospectServerAsync(reviewsClient, ct) - .ConfigureAwait(false); - var reviews2 = testServerFactory.Create( + testServers.Reviews2 = testServerFactory.Create( s => s .AddRouting() .AddSingleton() @@ -116,15 +133,8 @@ public static async Task CreateAsync(CancellationToken ct = default .UseWebSockets() .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(reviews2); - var reviews2Client = reviews2.CreateClient(); - reviews2Client.BaseAddress = new Uri("http://localhost:5000/graphql"); - var reviews2Schema = await IntrospectionClient - .IntrospectServerAsync(reviews2Client, ct) - .ConfigureAwait(false); - - var accounts = testServerFactory.Create( + testServers.Accounts = testServerFactory.Create( s => s .AddRouting() .AddSingleton() @@ -137,15 +147,8 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(accounts); - - var accountsClient = accounts.CreateClient(); - accountsClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var accountsSchema = await IntrospectionClient - .IntrospectServerAsync(accountsClient, ct) - .ConfigureAwait(false); - var products = testServerFactory.Create( + testServers.Products = testServerFactory.Create( s => s .AddRouting() .AddSingleton() @@ -159,15 +162,8 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(products); - - var productsClient = products.CreateClient(); - productsClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var productsSchema = await IntrospectionClient - .IntrospectServerAsync(productsClient, ct) - .ConfigureAwait(false); - var shipping = testServerFactory.Create( + testServers.Shipping = testServerFactory.Create( s => s .AddRouting() .AddGraphQLServer() @@ -177,15 +173,8 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(shipping); - var shippingClient = shipping.CreateClient(); - shippingClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var shippingSchema = await IntrospectionClient - .IntrospectServerAsync(shippingClient, ct) - .ConfigureAwait(false); - - var appointment = testServerFactory.Create( + testServers.Appointment = testServerFactory.Create( s => s .AddRouting() .AddGraphQLServer() @@ -197,15 +186,8 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(appointment); - - var appointmentClient = appointment.CreateClient(); - appointmentClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var appointmentSchema = await IntrospectionClient - .IntrospectServerAsync(appointmentClient, ct) - .ConfigureAwait(false); - var patient1 = testServerFactory.Create( + testServers.Patient1 = testServerFactory.Create( s => s .AddRouting() .AddGraphQLServer() @@ -215,15 +197,8 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(patient1); - - var patient1Client = patient1.CreateClient(); - patient1Client.BaseAddress = new Uri("http://localhost:5000/graphql"); - var patient1Schema = await IntrospectionClient - .IntrospectServerAsync(patient1Client, ct) - .ConfigureAwait(false); - var books = testServerFactory.Create( + testServers.Books = testServerFactory.Create( s => s .AddRouting() .AddGraphQLServer() @@ -232,15 +207,8 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(books); - var booksClient = books.CreateClient(); - booksClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var booksSchema = await IntrospectionClient - .IntrospectServerAsync(booksClient, ct) - .ConfigureAwait(false); - - var authors = testServerFactory.Create( + testServers.Authors = testServerFactory.Create( s => s .AddRouting() .AddGraphQLServer() @@ -249,195 +217,56 @@ public static async Task CreateAsync(CancellationToken ct = default c => c .UseRouting() .UseEndpoints(endpoints => endpoints.MapGraphQL())); - disposables.Add(authors); - var authorsClient = authors.CreateClient(); - authorsClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - var authorsSchema = await IntrospectionClient - .IntrospectServerAsync(authorsClient, ct) - .ConfigureAwait(false); + Debug.Assert(testServers.AllSet); - var httpClients = new Dictionary> + var httpClients = new Dictionary>((int)DemoProjectType.Count); + var webSocketClients = new Dictionary>((int)DemoProjectType.Count); + var subgraphs = DemoProjectValues.Create(); { + var httpBaseAddress = new Uri("http://localhost:5000/graphql"); + var wsBaseAddress = new Uri("ws://localhost:5000/graphql"); + for (var i = (DemoProjectType)0; i < DemoProjectType.Count; i++) { - "Reviews", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = reviews.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Reviews2", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = reviews2.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Accounts", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = accounts.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Products", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = products.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Shipping", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = shipping.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Appointment", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = appointment.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Patient1", () => - { - // ReSharper disable once AccessToDisposedClosure - var httpClient = patient1.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - { - "Books", () => + var testServer = testServers[i]; + + disposables.Add(testServer); + + var name = i.ToString(); + httpClients.Add(name, () => { // ReSharper disable once AccessToDisposedClosure - var httpClient = books.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); + var httpClient = testServer.CreateClient(); + httpClient.BaseAddress = httpBaseAddress; httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); return httpClient; - } - }, - { - "Authors", () => + }); + webSocketClients.Add(name, () => { - // ReSharper disable once AccessToDisposedClosure - var httpClient = books.CreateClient(); - httpClient.BaseAddress = new Uri("http://localhost:5000/graphql"); - httpClient.DefaultRequestHeaders.AddGraphQLPreflight(); - return httpClient; - } - }, - }; + var wsClient = testServer.CreateWebSocketClient(); + return new MockWebSocketConnection(wsClient); + }); + + var client = testServer.CreateClient(); + client.BaseAddress = httpBaseAddress; + var schema = await IntrospectionClient + .IntrospectServerAsync(client, ct) + .ConfigureAwait(false); + + subgraphs[i] = new DemoSubgraph( + name, + client.BaseAddress, + wsBaseAddress, + schema, + testServer); + } + } - var webSocketClients = new Dictionary> - { - { - "Reviews", () => new MockWebSocketConnection(reviews.CreateWebSocketClient()) - }, - { - "Reviews2", () => new MockWebSocketConnection(reviews2.CreateWebSocketClient()) - }, - { - "Accounts", () => new MockWebSocketConnection(accounts.CreateWebSocketClient()) - }, - { - "Products", () => new MockWebSocketConnection(products.CreateWebSocketClient()) - }, - { - "Shipping", () => new MockWebSocketConnection(shipping.CreateWebSocketClient()) - }, - { - "Appointment", () => new MockWebSocketConnection(appointment.CreateWebSocketClient()) - }, - { - "Patient1", () => new MockWebSocketConnection(patient1.CreateWebSocketClient()) - }, - { - "Books", () => new MockWebSocketConnection(books.CreateWebSocketClient()) - }, - { - "Authors", () => new MockWebSocketConnection(authors.CreateWebSocketClient()) - }, - }; + Debug.Assert(subgraphs.AllSet); return new DemoProject( disposables, - new DemoSubgraph( - "Accounts", - accountsClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - accountsSchema, - accounts), - new DemoSubgraph( - "Reviews", - reviewsClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - reviewsSchema, - reviews), - new DemoSubgraph( - "Reviews2", - reviews2Client.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - reviews2Schema, - reviews2), - new DemoSubgraph( - "Products", - productsClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - productsSchema, - products), - new DemoSubgraph( - "Shipping", - shippingClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - shippingSchema, - shipping), - new DemoSubgraph( - "Appointment", - appointmentClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - appointmentSchema, - appointment), - new DemoSubgraph( - "Patient1", - patient1Client.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - patient1Schema, - patient1), - new DemoSubgraph( - "Books", - booksClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - booksSchema, - books), - new DemoSubgraph( - "Authors", - authorsClient.BaseAddress, - new Uri("ws://localhost:5000/graphql"), - authorsSchema, - authors), + subgraphs, new MockHttpClientFactory(httpClients), new MockWebSocketConnectionFactory(webSocketClients)); } diff --git a/src/HotChocolate/Fusion/test/Shared/ErrorCompositionLog.cs b/src/HotChocolate/Fusion/test/Shared/ErrorCompositionLog.cs index 92f57f757f5..d48c14ab896 100644 --- a/src/HotChocolate/Fusion/test/Shared/ErrorCompositionLog.cs +++ b/src/HotChocolate/Fusion/test/Shared/ErrorCompositionLog.cs @@ -12,9 +12,9 @@ public sealed class ErrorCompositionLog : ICompositionLog public void Write(LogEntry entry) { - if(entry.Severity == LogSeverity.Error) + if (entry.Severity == LogSeverity.Error) { _errors.Add(entry); } } -} \ No newline at end of file +} From 3abd8cafa35ead41b37569f4ae65ec1bd23daa90 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Tue, 2 Jan 2024 11:11:31 +0200 Subject: [PATCH 3/7] Minor refactor and fix typos --- .../TestServerExtensions.cs | 3 ++- .../test/AspNetCore.Tests/EvictSchemaTests.cs | 7 +++++-- .../RequestExecutorServiceCollectionExtensions.cs | 2 +- .../Core/src/Types/SchemaBuilder.Setup.cs | 8 ++++++-- .../Fusion/src/Abstractions/FusionGraphPackage.cs | 8 +++++--- .../src/CommandLine/Commands/ComposeCommand.cs | 15 ++++++++++----- .../src/CommandLine/Helpers/PackageHelper.cs | 3 ++- .../FusionRequestExecutorBuilderExtensions.cs | 6 +++--- .../GatewayConfigurationTypeModule.cs | 5 ++--- .../Fusion/src/Core/Planning/QueryPlanner.cs | 1 - .../test/Core.Tests/ConfigurationRewriterTests.cs | 9 --------- .../Fusion/test/Core.Tests/DataTests.cs | 2 -- .../Fusion/test/Shared/DemoProject.cs | 2 +- .../Fusion/test/Shared/MockHttpClientFactory.cs | 4 +--- .../test/Shared/MockWebSocketConnectionFactory.cs | 4 +--- .../Fusion/test/Shared/TestCompositionLog.cs | 4 ++-- 16 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerExtensions.cs b/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerExtensions.cs index 1db35c26f7a..d22881379bf 100644 --- a/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerExtensions.cs +++ b/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerExtensions.cs @@ -233,8 +233,9 @@ public static async Task GetAsync( ClientQueryRequest request, string path = "/graphql") { + var query = request.ToString().Replace("+", "%2B"); var response = - await SendGetRequestAsync(testServer, request.ToString().Replace("+", "%2B"), path); + await SendGetRequestAsync(testServer, query, path); if (response.StatusCode == HttpStatusCode.NotFound) { diff --git a/src/HotChocolate/AspNetCore/test/AspNetCore.Tests/EvictSchemaTests.cs b/src/HotChocolate/AspNetCore/test/AspNetCore.Tests/EvictSchemaTests.cs index c2607b15254..33f6bb6c7e4 100644 --- a/src/HotChocolate/AspNetCore/test/AspNetCore.Tests/EvictSchemaTests.cs +++ b/src/HotChocolate/AspNetCore/test/AspNetCore.Tests/EvictSchemaTests.cs @@ -25,7 +25,8 @@ await server.GetAsync( // assert var time2 = await server.GetAsync( new ClientQueryRequest { Query = "{ time }" }); - Assert.False(((long)time1.Data!["time"]!).Equals((long)time2.Data!["time"]!)); + + Assert.False(Time(time1).Equals(Time(time2))); } [Fact] @@ -47,6 +48,8 @@ await server.GetAsync( var time2 = await server.GetAsync( new ClientQueryRequest { Query = "{ time }" }, "/evict"); - Assert.False(((long)time1.Data!["time"]!).Equals((long)time2.Data!["time"]!)); + Assert.False(Time(time1).Equals(Time(time2))); } + + private static long Time(ClientQueryResult t) => (long)t.Data!["time"]!; } diff --git a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs index 8ec1a4c30c2..7ee20357323 100644 --- a/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs +++ b/src/HotChocolate/Core/src/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs @@ -169,7 +169,7 @@ private static IRequestExecutorBuilder CreateBuilder( (sp, e) => { e.OnRequestExecutorEvictedHooks.Add( - // when ever we evict this schema we will clear the caches. + // Whenever we evict this schema, we will clear the caches. new OnRequestExecutorEvictedAction( _ => sp.GetRequiredService().Clear())); }); diff --git a/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs b/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs index e988b1300d7..213e026e41d 100644 --- a/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs +++ b/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs @@ -184,8 +184,12 @@ private static void RegisterOperationName( OperationType operation, string? typeName) { - if (!builder._operations.ContainsKey(operation) - && !string.IsNullOrEmpty(typeName)) + if (string.IsNullOrEmpty(typeName)) + { + return; + } + + if (!builder._operations.ContainsKey(operation)) { builder._operations.Add( operation, diff --git a/src/HotChocolate/Fusion/src/Abstractions/FusionGraphPackage.cs b/src/HotChocolate/Fusion/src/Abstractions/FusionGraphPackage.cs index 75c43c16460..90a148e8b36 100644 --- a/src/HotChocolate/Fusion/src/Abstractions/FusionGraphPackage.cs +++ b/src/HotChocolate/Fusion/src/Abstractions/FusionGraphPackage.cs @@ -69,7 +69,8 @@ public static FusionGraphPackage Open( throw new ArgumentOutOfRangeException(nameof(access)); } - var package = Package.Open(stream, FileMode.OpenOrCreate, access); + // ReSharper disable once AccessToStaticMemberViaDerivedType + var package = ZipPackage.Open(stream, FileMode.OpenOrCreate, access); return new FusionGraphPackage(package); } @@ -107,7 +108,8 @@ public static FusionGraphPackage Open( var mode = access == FileAccess.Read ? FileMode.Open : FileMode.OpenOrCreate; - var package = Package.Open(path, mode, access); + // ReSharper disable once AccessToStaticMemberViaDerivedType + var package = ZipPackage.Open(path, mode, access); return new FusionGraphPackage(package); } @@ -560,7 +562,7 @@ private async Task ReadSubgraphConfigurationAsync( return new SubgraphConfiguration( config.Name, - schema.ToString(true), + schema.ToString(indented: true), extensions.Select(t => t.ToString(_syntaxSerializerOptions)).ToArray(), config.Clients, config.Extensions); diff --git a/src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs b/src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs index 57e6c447ae4..6854f12620d 100644 --- a/src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs +++ b/src/HotChocolate/Fusion/src/CommandLine/Commands/ComposeCommand.cs @@ -88,11 +88,11 @@ private static async Task ExecuteAsync( if (settingsFile is null) { - var settingsFileName = System.IO.Path.GetFileNameWithoutExtension(packageFile.FullName) + "-settings.json"; + var settingsFileName = IOPath.GetFileNameWithoutExtension(packageFile.FullName) + "-settings.json"; if (packageFile.DirectoryName is not null) { - settingsFileName = System.IO.Path.Combine(packageFile.DirectoryName, settingsFileName); + settingsFileName = IOPath.Combine(packageFile.DirectoryName, settingsFileName); } settingsFile = new FileInfo(settingsFileName); @@ -109,12 +109,17 @@ private static async Task ExecuteAsync( } } - var configs = (await package.GetSubgraphConfigurationsAsync(cancellationToken)).ToDictionary(t => t.Name); + var configs = (await package.GetSubgraphConfigurationsAsync(cancellationToken)) + .ToDictionary(t => t.Name); // resolve subgraph packages will scan the directory for fsp's. In case of remove we don't want to do that. if (removeSubgraphs is not { Count: > 0 } || subgraphPackageFiles is { Count: > 0 }) { - await ResolveSubgraphPackagesAsync(workingDirectory, subgraphPackageFiles, configs, cancellationToken); + await ResolveSubgraphPackagesAsync( + workingDirectory, + subgraphPackageFiles, + configs, + cancellationToken); } using var settingsJson = settingsFile.Exists @@ -389,4 +394,4 @@ public sealed class Transport [JsonPropertyOrder(10)] public string? DefaultClientName { get; set; } = "Fusion"; } -} \ No newline at end of file +} diff --git a/src/HotChocolate/Fusion/src/CommandLine/Helpers/PackageHelper.cs b/src/HotChocolate/Fusion/src/CommandLine/Helpers/PackageHelper.cs index 89a4d4aaacb..36573ecaf45 100644 --- a/src/HotChocolate/Fusion/src/CommandLine/Helpers/PackageHelper.cs +++ b/src/HotChocolate/Fusion/src/CommandLine/Helpers/PackageHelper.cs @@ -46,7 +46,8 @@ public static async Task CreateSubgraphPackageAsync( extensions.Add(await LoadSchemaDocumentAsync(extensionFile, ct)); } - using var package = Package.Open(packageFile, FileMode.Create); + // ReSharper disable once AccessToStaticMemberViaDerivedType + using var package = ZipPackage.Open(packageFile, FileMode.Create); await AddSchemaToPackageAsync(package, schema); await AddTransportConfigToPackage(package, transportConfig); await AddSchemaExtensionsToPackage(package, extensions); diff --git a/src/HotChocolate/Fusion/src/Core/DependencyInjection/FusionRequestExecutorBuilderExtensions.cs b/src/HotChocolate/Fusion/src/Core/DependencyInjection/FusionRequestExecutorBuilderExtensions.cs index cf07a99baca..053422791b7 100644 --- a/src/HotChocolate/Fusion/src/Core/DependencyInjection/FusionRequestExecutorBuilderExtensions.cs +++ b/src/HotChocolate/Fusion/src/Core/DependencyInjection/FusionRequestExecutorBuilderExtensions.cs @@ -21,7 +21,7 @@ public static class FusionRequestExecutorBuilderExtensions /// Adds a Fusion GraphQL Gateway to the service collection. /// /// - /// The service collection.1 + /// The service collection. /// /// /// The name of the fusion graph. @@ -78,7 +78,7 @@ public static FusionGatewayBuilder AddFusionGatewayServer( return new FusionGatewayBuilder(builder); } - + /// /// Adds a custom ID parser to the gateway. /// @@ -95,7 +95,7 @@ public static FusionGatewayBuilder AddNodeIdParser( sc.RemoveAll(); sc.AddSingleton(); })); - + return builder; } diff --git a/src/HotChocolate/Fusion/src/Core/DependencyInjection/GatewayConfigurationTypeModule.cs b/src/HotChocolate/Fusion/src/Core/DependencyInjection/GatewayConfigurationTypeModule.cs index 2de3fd36f78..0ec31078e2d 100644 --- a/src/HotChocolate/Fusion/src/Core/DependencyInjection/GatewayConfigurationTypeModule.cs +++ b/src/HotChocolate/Fusion/src/Core/DependencyInjection/GatewayConfigurationTypeModule.cs @@ -1,11 +1,9 @@ using HotChocolate; using HotChocolate.Execution.Configuration; -using HotChocolate.Fusion; using HotChocolate.Fusion.Metadata; using HotChocolate.Fusion.Utilities; using HotChocolate.Language; using HotChocolate.Types; -using HotChocolate.Types.Descriptors.Definitions; using static System.Threading.Tasks.TaskCreationOptions; namespace Microsoft.Extensions.DependencyInjection; @@ -44,7 +42,7 @@ public GatewayConfigurationTypeModule( () => _ready.TrySetCanceled()); } - internal override async ValueTask ConfigureAsync( + protected internal override async ValueTask ConfigureAsync( ConfigurationContext context, CancellationToken cancellationToken) { @@ -81,6 +79,7 @@ private static void ApplyConfiguration(ISchemaBuilder schemaBuilder, DocumentNod .AddDocument(schemaDoc) .SetFusionGraphConfig(fusionGraphConfig); + // TODO: This shouldn't be here, surely. if (schemaDoc.Definitions.Any(t => t is ScalarTypeDefinitionNode { Name.Value: "Upload" })) { schemaBuilder.AddType(); diff --git a/src/HotChocolate/Fusion/src/Core/Planning/QueryPlanner.cs b/src/HotChocolate/Fusion/src/Core/Planning/QueryPlanner.cs index 10ad824beda..f4a040c45d2 100644 --- a/src/HotChocolate/Fusion/src/Core/Planning/QueryPlanner.cs +++ b/src/HotChocolate/Fusion/src/Core/Planning/QueryPlanner.cs @@ -26,7 +26,6 @@ public QueryPlanner(FusionGraphConfiguration configuration, ISchema schema) public QueryPlan Plan(IOperation operation) { - var queryPlanContext = new QueryPlanContext(operation); _pipeline(queryPlanContext); diff --git a/src/HotChocolate/Fusion/test/Core.Tests/ConfigurationRewriterTests.cs b/src/HotChocolate/Fusion/test/Core.Tests/ConfigurationRewriterTests.cs index ccd5b87d67f..2fa4bddd513 100644 --- a/src/HotChocolate/Fusion/test/Core.Tests/ConfigurationRewriterTests.cs +++ b/src/HotChocolate/Fusion/test/Core.Tests/ConfigurationRewriterTests.cs @@ -1,20 +1,11 @@ using CookieCrumble; -using HotChocolate.Execution; -using HotChocolate.Execution.Configuration; using HotChocolate.Fusion.Composition; using HotChocolate.Fusion.Metadata; -using HotChocolate.Fusion.Planning; using HotChocolate.Fusion.Shared; -using HotChocolate.Language; using HotChocolate.Skimmed.Serialization; -using HotChocolate.Types.Relay; -using Microsoft.Extensions.DependencyInjection; using Xunit.Abstractions; using static HotChocolate.Fusion.Shared.DemoProjectSchemaExtensions; -using static HotChocolate.Language.Utf8GraphQLParser; -using static HotChocolate.Fusion.TestHelper; using HttpClientConfiguration = HotChocolate.Fusion.Metadata.HttpClientConfiguration; -using HotChocolate.Utilities; namespace HotChocolate.Fusion; diff --git a/src/HotChocolate/Fusion/test/Core.Tests/DataTests.cs b/src/HotChocolate/Fusion/test/Core.Tests/DataTests.cs index 600ae061c63..c2b83b0760f 100644 --- a/src/HotChocolate/Fusion/test/Core.Tests/DataTests.cs +++ b/src/HotChocolate/Fusion/test/Core.Tests/DataTests.cs @@ -1,10 +1,8 @@ using CookieCrumble; using HotChocolate.Execution; using HotChocolate.Fusion.Composition; -using HotChocolate.Fusion.Composition.Features; using HotChocolate.Fusion.Shared; using HotChocolate.Skimmed.Serialization; -using HotChocolate.Types.Relay; using Microsoft.Extensions.DependencyInjection; using Xunit.Abstractions; using static HotChocolate.Fusion.Shared.DemoProjectSchemaExtensions; diff --git a/src/HotChocolate/Fusion/test/Shared/DemoProject.cs b/src/HotChocolate/Fusion/test/Shared/DemoProject.cs index 93065121447..48c4c48044e 100644 --- a/src/HotChocolate/Fusion/test/Shared/DemoProject.cs +++ b/src/HotChocolate/Fusion/test/Shared/DemoProject.cs @@ -247,7 +247,7 @@ public static async Task CreateAsync(CancellationToken ct = default return new MockWebSocketConnection(wsClient); }); - var client = testServer.CreateClient(); + using var client = testServer.CreateClient(); client.BaseAddress = httpBaseAddress; var schema = await IntrospectionClient .IntrospectServerAsync(client, ct) diff --git a/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs b/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs index 3d2f9c05574..8f92105a0d5 100644 --- a/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs +++ b/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs @@ -5,9 +5,7 @@ public class MockHttpClientFactory : IHttpClientFactory private readonly Dictionary> _clients; public MockHttpClientFactory(Dictionary> clients) - { - _clients = clients; - } + => _clients = clients; public HttpClient CreateClient(string name) => _clients[name].Invoke(); diff --git a/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs b/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs index 7b4ce153808..a043a006272 100644 --- a/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs +++ b/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs @@ -10,9 +10,7 @@ public class MockWebSocketConnectionFactory : IWebSocketConnectionFactory private readonly Dictionary> _clients; public MockWebSocketConnectionFactory(Dictionary> clients) - { - _clients = clients; - } + => _clients = clients; public IWebSocketConnection CreateConnection(string name) => _clients[name].Invoke(); diff --git a/src/HotChocolate/Fusion/test/Shared/TestCompositionLog.cs b/src/HotChocolate/Fusion/test/Shared/TestCompositionLog.cs index 56c61d948d8..2beb417243e 100644 --- a/src/HotChocolate/Fusion/test/Shared/TestCompositionLog.cs +++ b/src/HotChocolate/Fusion/test/Shared/TestCompositionLog.cs @@ -16,11 +16,11 @@ public TestCompositionLog(ITestOutputHelper output) public void Write(LogEntry entry) { - if(entry.Severity == LogSeverity.Error) + if (entry.Severity == LogSeverity.Error) { HasErrors = true; } _output.WriteLine(entry.Message); } -} \ No newline at end of file +} From bf1b21f972117bc61ca7feddd2a9f2902487819f Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Tue, 2 Jan 2024 11:11:58 +0200 Subject: [PATCH 4/7] Minor breaking changes --- .../Execution/Configuration/ITypeModule.cs | 2 +- .../Commands/SubgraphPackCommand.cs | 20 ++++++++++++++----- .../Shared/MockWebSocketConnectionFactory.cs | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/HotChocolate/Core/src/Execution/Configuration/ITypeModule.cs b/src/HotChocolate/Core/src/Execution/Configuration/ITypeModule.cs index 247e95a5326..bdb716849c1 100644 --- a/src/HotChocolate/Core/src/Execution/Configuration/ITypeModule.cs +++ b/src/HotChocolate/Core/src/Execution/Configuration/ITypeModule.cs @@ -50,7 +50,7 @@ public abstract class TypeModule : ITypeModule /// public event EventHandler? TypesChanged; - internal virtual ValueTask ConfigureAsync( + protected internal virtual ValueTask ConfigureAsync( ConfigurationContext context, CancellationToken cancellationToken) => default; diff --git a/src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs b/src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs index 4dc97766ef9..13b5c1a2094 100644 --- a/src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs +++ b/src/HotChocolate/Fusion/src/CommandLine/Commands/SubgraphPackCommand.cs @@ -53,16 +53,18 @@ private static async Task ExecuteAsync( new FileInfo(Combine(workingDirectory.FullName, ExtensionFile)), }; + bool hasErrors = false; + if (!schemaFile.Exists) { console.WriteLine($"The schema file `{schemaFile.FullName}` does not exist."); - return; + hasErrors = true; } if (!configFile.Exists) { console.WriteLine($"The config file `{configFile.FullName}` does not exist."); - return; + hasErrors = true; } if (extensionFiles.Count == 0) @@ -77,10 +79,18 @@ private static async Task ExecuteAsync( extensionFiles.Clear(); } - if (extensionFiles.Any(t => !t.Exists)) { - console.WriteLine( - $"The extension file `{extensionFiles.First(t => !t.Exists).FullName}` does not exist."); + var firstNonExistentFile = extensionFiles.FirstOrDefault(t => !t.Exists); + if (firstNonExistentFile is not null) + { + console.WriteLine( + $"The extension file `{firstNonExistentFile.FullName}` does not exist."); + hasErrors = true; + } + } + + if (hasErrors) + { return; } diff --git a/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs b/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs index a043a006272..accd7860608 100644 --- a/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs +++ b/src/HotChocolate/Fusion/test/Shared/MockWebSocketConnectionFactory.cs @@ -5,7 +5,7 @@ namespace HotChocolate.Fusion.Shared; -public class MockWebSocketConnectionFactory : IWebSocketConnectionFactory +public sealed class MockWebSocketConnectionFactory : IWebSocketConnectionFactory { private readonly Dictionary> _clients; From 2329e1f415bbdb08fd1370d5f80592bc4f82dcd9 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Tue, 2 Jan 2024 12:08:46 +0200 Subject: [PATCH 5/7] Reuse common method for directive creation --- .../SchemaBuilderExtensions.Resolvers.cs | 22 +++--- .../Fusion/src/Composition/FusionTypes.cs | 68 ++++++++++++------- 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Resolvers.cs b/src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Resolvers.cs index 5a31953b514..ea478add718 100644 --- a/src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Resolvers.cs +++ b/src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Resolvers.cs @@ -716,18 +716,20 @@ private static ISchemaBuilder AddResolverTypeInternal( private static void InitializeResolverTypeInterceptor(ISchemaBuilder builder) { - if (!builder.ContextData.ContainsKey(WellKnownContextData.ResolverConfigs)) + if (builder.ContextData.ContainsKey(WellKnownContextData.ResolverConfigs)) { - var resolverConfigs = new List(); - var resolverTypes = new List<(string, Type)>(); - var runtimeTypes = new Dictionary(); + return; + } - builder.ContextData.Add(WellKnownContextData.ResolverConfigs, resolverConfigs); - builder.ContextData.Add(WellKnownContextData.ResolverTypes, resolverTypes); - builder.ContextData.Add(WellKnownContextData.RuntimeTypes, runtimeTypes); + var resolverConfigs = new List(); + var resolverTypes = new List<(string, Type)>(); + var runtimeTypes = new Dictionary(); - builder.TryAddTypeInterceptor( - new ResolverTypeInterceptor(resolverConfigs, resolverTypes, runtimeTypes)); - } + builder.ContextData.Add(WellKnownContextData.ResolverConfigs, resolverConfigs); + builder.ContextData.Add(WellKnownContextData.ResolverTypes, resolverTypes); + builder.ContextData.Add(WellKnownContextData.RuntimeTypes, runtimeTypes); + + builder.TryAddTypeInterceptor( + new ResolverTypeInterceptor(resolverConfigs, resolverTypes, runtimeTypes)); } } diff --git a/src/HotChocolate/Fusion/src/Composition/FusionTypes.cs b/src/HotChocolate/Fusion/src/Composition/FusionTypes.cs index 2d255e01ce0..2c1f53be980 100644 --- a/src/HotChocolate/Fusion/src/Composition/FusionTypes.cs +++ b/src/HotChocolate/Fusion/src/Composition/FusionTypes.cs @@ -322,19 +322,43 @@ private DirectiveType RegisterNodeDirectiveType(string name, ScalarType typeName return directiveType; } + private Directive CreateTransportDirective( + string subgraphName, + string? clientName, + Uri location, + string kind) + { + Argument[] arguments; + { + var argumentCount = 3; + if (clientName is not null) + { + argumentCount++; + } + arguments = new Argument[argumentCount]; + } + + var i = 0; + arguments[i++] = new Argument(SubgraphArg, subgraphName); + if (clientName is not null) + { + arguments[i++] = new Argument(ClientGroupArg, clientName); + } + arguments[i++] = new Argument(LocationArg, location.ToString()); + arguments[i] = new Argument(KindArg, kind); + + return new Directive(Transport, (IReadOnlyList) arguments); + } + public Directive CreateHttpDirective(string subgraphName, string? clientName, Uri location) - => clientName is null - ? new Directive( - Transport, - new Argument(SubgraphArg, subgraphName), - new Argument(LocationArg, location.ToString()), - new Argument(KindArg, "HTTP")) - : new Directive( - Transport, - new Argument(SubgraphArg, subgraphName), - new Argument(ClientGroupArg, clientName), - new Argument(LocationArg, location.ToString()), - new Argument(KindArg, "HTTP")); + { + var result = CreateTransportDirective( + subgraphName: subgraphName, + clientName: clientName, + location: location, + kind: "HTTP"); + return result; + } private DirectiveType RegisterTransportDirectiveType( string name, @@ -354,18 +378,14 @@ private DirectiveType RegisterTransportDirectiveType( } public Directive CreateWebSocketDirective(string subgraphName, string? clientName, Uri location) - => clientName is null - ? new Directive( - Transport, - new Argument(SubgraphArg, subgraphName), - new Argument(LocationArg, location.ToString()), - new Argument(KindArg, "WebSocket")) - : new Directive( - Transport, - new Argument(SubgraphArg, subgraphName), - new Argument(ClientGroupArg, clientName), - new Argument(LocationArg, location.ToString()), - new Argument(KindArg, "WebSocket")); + { + var result = CreateTransportDirective( + subgraphName: subgraphName, + clientName: clientName, + location: location, + kind: "WebSocket"); + return result; + } private DirectiveType RegisterFusionDirectiveType( string name, From b561d62c21a183d3ab9ceba686a29a799ed87a07 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Wed, 10 Jan 2024 18:16:53 +0200 Subject: [PATCH 6/7] Seal a few classes --- .../test/AspNetCore.Tests.Utilities/TestServerFactory.cs | 4 ++-- src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerFactory.cs b/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerFactory.cs index e4fb20731f7..7c4f7383222 100644 --- a/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerFactory.cs +++ b/src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerFactory.cs @@ -5,12 +5,12 @@ namespace HotChocolate.AspNetCore.Tests.Utilities; -public class TestServerFactory : IDisposable +public sealed class TestServerFactory : IDisposable { private readonly List _instances = new(); public TestServer Create( - Action configureServices, + Action? configureServices, Action configureApplication) { var builder = new WebHostBuilder() diff --git a/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs b/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs index 8f92105a0d5..20529f1eefc 100644 --- a/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs +++ b/src/HotChocolate/Fusion/test/Shared/MockHttpClientFactory.cs @@ -1,6 +1,6 @@ namespace HotChocolate.Fusion.Shared; -public class MockHttpClientFactory : IHttpClientFactory +public sealed class MockHttpClientFactory : IHttpClientFactory { private readonly Dictionary> _clients; From a5b3fe7d6e303548bd2908d9a9986da7f6925a2f Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Wed, 10 Jan 2024 18:56:15 +0200 Subject: [PATCH 7/7] Refactor compose --- .../MergeQueryAndMutationTypeMiddleware.cs | 29 +++++++++---------- .../src/Skimmed/DirectiveCollection.cs | 9 ++---- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/HotChocolate/Fusion/src/Composition/Pipeline/MergeQueryAndMutationTypeMiddleware.cs b/src/HotChocolate/Fusion/src/Composition/Pipeline/MergeQueryAndMutationTypeMiddleware.cs index 48189dcbff1..4a0e594f77d 100644 --- a/src/HotChocolate/Fusion/src/Composition/Pipeline/MergeQueryAndMutationTypeMiddleware.cs +++ b/src/HotChocolate/Fusion/src/Composition/Pipeline/MergeQueryAndMutationTypeMiddleware.cs @@ -22,21 +22,20 @@ public async ValueTask InvokeAsync(CompositionContext context, MergeDelegate nex { if (schema.QueryType is not null) { - var targetType = context.FusionGraph.QueryType!; - - if (context.FusionGraph.QueryType is null) + if (context.FusionGraph.QueryType is not { } targetType) { - targetType = context.FusionGraph.QueryType = new ObjectType(schema.QueryType.Name); + targetType = new ObjectType(schema.QueryType.Name); + context.FusionGraph.QueryType = targetType; targetType.MergeDescriptionWith(schema.QueryType); context.FusionGraph.Types.Add(targetType); } MergeRootFields( - context, - schema, - schema.QueryType, - targetType, - OperationType.Query, + context, + schema, + schema.QueryType, + targetType, + OperationType.Query, skipOnQuery); } @@ -106,13 +105,13 @@ private static void MergeRootFields( var arguments = new List(); var selection = new FieldNode( - null, - new NameNode(field.GetOriginalName()), - null, - null, + location: null, + name: new NameNode(field.GetOriginalName()), + alias: null, + required: null, Array.Empty(), arguments, - null); + selectionSet: null); var selectionSet = new SelectionSetNode(new[] { selection }); @@ -182,4 +181,4 @@ private static Directive CreateVariableDirective( subgraphName, variableName, variableName); -} \ No newline at end of file +} diff --git a/src/HotChocolate/Skimmed/src/Skimmed/DirectiveCollection.cs b/src/HotChocolate/Skimmed/src/Skimmed/DirectiveCollection.cs index 2fa3370b876..3f2aaa71bc1 100644 --- a/src/HotChocolate/Skimmed/src/Skimmed/DirectiveCollection.cs +++ b/src/HotChocolate/Skimmed/src/Skimmed/DirectiveCollection.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Runtime.InteropServices; using HotChocolate.Utilities; namespace HotChocolate.Skimmed; @@ -85,12 +86,7 @@ public void Clear() => _directives.Clear(); public void CopyTo(Directive[] array, int arrayIndex) - { - foreach (var directive in _directives) - { - array[arrayIndex++] = directive; - } - } + => _directives.CopyTo(array, arrayIndex); /// public IEnumerator GetEnumerator() @@ -98,5 +94,4 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - }