From c966f797f5c2410a8aa6d83c30ec9ca018c2119f Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Thu, 11 Jan 2024 16:03:30 +0200 Subject: [PATCH 1/6] Make AcceptMedia thing public --- src/HotChocolate/AspNetCore/src/AspNetCore/AcceptMediaType.cs | 2 +- src/HotChocolate/AspNetCore/src/AspNetCore/HeaderUtilities.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/AcceptMediaType.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/AcceptMediaType.cs index 6c0dcedf5ed..3da9bd852f6 100644 --- a/src/HotChocolate/AspNetCore/src/AspNetCore/AcceptMediaType.cs +++ b/src/HotChocolate/AspNetCore/src/AspNetCore/AcceptMediaType.cs @@ -26,7 +26,7 @@ public readonly struct AcceptMediaType /// /// Type or subtype are empty. /// - internal AcceptMediaType( + public AcceptMediaType( StringSegment type, StringSegment subType, double? quality, diff --git a/src/HotChocolate/AspNetCore/src/AspNetCore/HeaderUtilities.cs b/src/HotChocolate/AspNetCore/src/AspNetCore/HeaderUtilities.cs index d2b0b9d2b20..3684a4560f5 100644 --- a/src/HotChocolate/AspNetCore/src/AspNetCore/HeaderUtilities.cs +++ b/src/HotChocolate/AspNetCore/src/AspNetCore/HeaderUtilities.cs @@ -11,7 +11,7 @@ namespace HotChocolate.AspNetCore; /// /// Utilities for handling HTTP headers. /// -internal static class HeaderUtilities +public static class HeaderUtilities { private static readonly ConcurrentDictionary _cache = new(StringComparer.Ordinal); @@ -147,7 +147,7 @@ public CacheEntry(string key, MediaTypeHeaderValue value) public DateTime CreatedAt { get; } } - internal readonly struct AcceptHeaderResult + public readonly struct AcceptHeaderResult { public AcceptHeaderResult(AcceptMediaType[] acceptMediaTypes) { From b3077df94f3a9879a20468c97eb0f57ac3091043 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Thu, 11 Jan 2024 18:54:06 +0200 Subject: [PATCH 2/6] Inline utf8 constants --- .../Utf8GraphQLRequestParser.Constants.cs | 80 +------------------ .../Language.Web/Utf8GraphQLRequestParser.cs | 12 +-- 2 files changed, 7 insertions(+), 85 deletions(-) diff --git a/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.Constants.cs b/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.Constants.cs index b284d601887..63d5969cd5f 100644 --- a/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.Constants.cs +++ b/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.Constants.cs @@ -5,7 +5,6 @@ namespace HotChocolate.Language; public ref partial struct Utf8GraphQLRequestParser { private const byte _o = (byte)'o'; - private const byte _n = (byte)'n'; private const byte _q = (byte)'q'; private const byte _v = (byte)'v'; private const byte _e = (byte)'e'; @@ -13,82 +12,5 @@ public ref partial struct Utf8GraphQLRequestParser private const byte _i = (byte)'i'; private const byte _p = (byte)'p'; - // This uses C# compiler's ability to refer to static data directly. For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static - private static ReadOnlySpan OperationName => new[] - { - (byte)'o', - (byte)'p', - (byte)'e', - (byte)'r', - (byte)'a', - (byte)'t', - (byte)'i', - (byte)'o', - (byte)'n', - (byte)'N', - (byte)'a', - (byte)'m', - (byte)'e', - }; - - private static ReadOnlySpan Query => new[] - { - (byte)'q', - (byte)'u', - (byte)'e', - (byte)'r', - (byte)'y', - }; - - private static ReadOnlySpan Variables => new[] - { - (byte)'v', - (byte)'a', - (byte)'r', - (byte)'i', - (byte)'a', - (byte)'b', - (byte)'l', - (byte)'e', - (byte)'s', - }; - - private static ReadOnlySpan Extensions => new[] - { - (byte)'e', - (byte)'x', - (byte)'t', - (byte)'e', - (byte)'n', - (byte)'s', - (byte)'i', - (byte)'o', - (byte)'n', - (byte)'s', - }; - - private static ReadOnlySpan Type => new[] - { - (byte)'t', - (byte)'y', - (byte)'p', - (byte)'e', - }; - - private static ReadOnlySpan Id => new[] - { - (byte)'i', - (byte)'d', - }; - - private static ReadOnlySpan Payload => new[] - { - (byte)'p', - (byte)'a', - (byte)'y', - (byte)'l', - (byte)'o', - (byte)'a', - (byte)'d', - }; + private static ReadOnlySpan Id => "id"u8; } diff --git a/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.cs b/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.cs index 8000322873b..6eb3339f903 100644 --- a/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.cs +++ b/src/HotChocolate/Language/src/Language.Web/Utf8GraphQLRequestParser.cs @@ -142,7 +142,7 @@ private void ParseRequestProperty(ref Request request) switch (fieldName[0]) { case _o: - if (fieldName.SequenceEqual(OperationName)) + if (fieldName.SequenceEqual("operationName"u8)) { request.OperationName = ParseStringOrNull(); } @@ -156,7 +156,7 @@ private void ParseRequestProperty(ref Request request) break; case _q: - if (fieldName.SequenceEqual(Query)) + if (fieldName.SequenceEqual("query"u8)) { request.HasQuery = !IsNullToken(); @@ -171,14 +171,14 @@ private void ParseRequestProperty(ref Request request) break; case _v: - if (fieldName.SequenceEqual(Variables)) + if (fieldName.SequenceEqual("variables"u8)) { request.Variables = ParseVariables(); } break; case _e: - if (fieldName.SequenceEqual(Extensions)) + if (fieldName.SequenceEqual("extensions"u8)) { request.Extensions = ParseObjectOrNull(); } @@ -198,7 +198,7 @@ private void ParseMessageProperty(ref Message message) switch (fieldName[0]) { case _t: - if (fieldName.SequenceEqual(Type)) + if (fieldName.SequenceEqual("type"u8)) { message.Type = ParseStringOrNull(); } @@ -212,7 +212,7 @@ private void ParseMessageProperty(ref Message message) break; case _p: - if (fieldName.SequenceEqual(Payload)) + if (fieldName.SequenceEqual("payload"u8)) { var start = _reader.Start; var hasPayload = !IsNullToken(); From a107577f255244103f66bd26ae5964cdc5aa09ef Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Fri, 12 Jan 2024 19:42:30 +0200 Subject: [PATCH 3/6] Fix typo --- src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs b/src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs index c3ec461ebcf..3ba9af6138f 100644 --- a/src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs +++ b/src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs @@ -94,7 +94,7 @@ public interface IReadOnlySchemaOptions DirectiveVisibility DefaultDirectiveVisibility { get; } /// - /// Defines that the default resolver execution strategy. + /// Defines the default resolver execution strategy. /// ExecutionStrategy DefaultResolverStrategy { get; } @@ -102,7 +102,7 @@ public interface IReadOnlySchemaOptions /// Defines if the order of important middleware components shall be validated. /// bool ValidatePipelineOrder { get; } - + /// /// Defines if the runtime types of types shall be validated. /// From 6b517ed903bc254f63914c4b71ba16091df52f1f Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Fri, 12 Jan 2024 19:42:48 +0200 Subject: [PATCH 4/6] Fix formatting --- .../Types/Types/Introspection/IntrospectionTypeInterceptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HotChocolate/Core/src/Types/Types/Introspection/IntrospectionTypeInterceptor.cs b/src/HotChocolate/Core/src/Types/Types/Introspection/IntrospectionTypeInterceptor.cs index d4a97173311..483ce5d68bf 100644 --- a/src/HotChocolate/Core/src/Types/Types/Introspection/IntrospectionTypeInterceptor.cs +++ b/src/HotChocolate/Core/src/Types/Types/Introspection/IntrospectionTypeInterceptor.cs @@ -31,7 +31,7 @@ public override void OnAfterCompleteName( ITypeCompletionContext completionContext, DefinitionBase definition) { - if(completionContext.Type is ObjectType && definition is ObjectTypeDefinition typeDef) + if (completionContext.Type is ObjectType && definition is ObjectTypeDefinition typeDef) { _objectTypeDefinitions.Add(typeDef); } From 0e64d0b55861e76b0ce3c6b5762a2bf75cf2f3f0 Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Tue, 19 Dec 2023 12:19:24 +0200 Subject: [PATCH 5/6] Apply braces code style in solution (move to another branch?) --- .../Helpers/MockFunctionContext.cs | 2 ++ .../Helpers/MockHttpRequestData.cs | 2 ++ .../HotChocolate.OpenApi/OpenApiWrapperPipelineBuilder.cs | 6 +++++- .../Pipeline/CreateInputTypesMiddleware.cs | 6 +++++- .../Pipeline/CreateMutationTypeMiddleware.cs | 5 ++++- .../Pipeline/DiscoverOperationsMiddleware.cs | 6 +++++- .../Controller/PetStoreController.cs | 6 +++++- .../Client/src/Core/Serialization/Iso8601Duration.cs | 4 ++++ 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockFunctionContext.cs b/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockFunctionContext.cs index 1be21962d01..882b9ada25c 100644 --- a/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockFunctionContext.cs +++ b/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockFunctionContext.cs @@ -87,7 +87,9 @@ public class MockInvocationFeatures : Dictionary, IInvocationFeatu public void Set(T instance) { if (instance == null) + { return; + } TryAdd(typeof(T), instance); } diff --git a/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs b/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs index 06d072db584..47d104c27fc 100644 --- a/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs +++ b/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs @@ -30,7 +30,9 @@ public MockHttpRequestData( Url = requestUri ?? throw new ArgumentNullException(nameof(requestUri)); if(claimsIdentities != null) + { Identities = claimsIdentities; + } if (!string.IsNullOrEmpty(requestBody)) { diff --git a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/OpenApiWrapperPipelineBuilder.cs b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/OpenApiWrapperPipelineBuilder.cs index 59a8e10773b..367839c6a2b 100644 --- a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/OpenApiWrapperPipelineBuilder.cs +++ b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/OpenApiWrapperPipelineBuilder.cs @@ -11,7 +11,11 @@ private OpenApiWrapperPipelineBuilder() public OpenApiWrapperDelegate Build() { OpenApiWrapperDelegate next = _ => { }; - for (var i = _pipeline.Count - 1; i >= 0; i--) next = _pipeline[i].Invoke(next); + for (var i = _pipeline.Count - 1; i >= 0; i--) + { + next = _pipeline[i].Invoke(next); + } + return next; } diff --git a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateInputTypesMiddleware.cs b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateInputTypesMiddleware.cs index 11d1ae71d95..3c64bc0e5d1 100644 --- a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateInputTypesMiddleware.cs +++ b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateInputTypesMiddleware.cs @@ -79,7 +79,11 @@ private static void AddInputType(OpenApiWrapperContext context, Operation operat private static void AddIfNecessary(OpenApiWrapperContext context, InputObjectType inputObjectType) { - if (context.MutableSchema.Types.ContainsName(inputObjectType.Name)) return; + if (context.MutableSchema.Types.ContainsName(inputObjectType.Name)) + { + return; + } + context.MutableSchema.Types.Add(inputObjectType); } diff --git a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateMutationTypeMiddleware.cs b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateMutationTypeMiddleware.cs index 9bac554ab20..ab10fe1d5db 100644 --- a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateMutationTypeMiddleware.cs +++ b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/CreateMutationTypeMiddleware.cs @@ -23,7 +23,10 @@ private static void CreateMutationType(OpenApiWrapperContext context) { var operations = context.GetMutationOperations(); - if (operations.Count == 0) return; + if (operations.Count == 0) + { + return; + } var mutationType = new ObjectType(OpenApiResources.RootTypeMutation); diff --git a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/DiscoverOperationsMiddleware.cs b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/DiscoverOperationsMiddleware.cs index 49eb04cad2d..62bc40b4344 100644 --- a/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/DiscoverOperationsMiddleware.cs +++ b/src/HotChocolate/OpenApi/src/HotChocolate.OpenApi/Pipeline/DiscoverOperationsMiddleware.cs @@ -41,7 +41,11 @@ public void Invoke(OpenApiWrapperContext context, OpenApiWrapperDelegate next) resultOperation.AddParameter(openApiParameter); } - if (context.Operations.ContainsKey(resultOperation.OperationId)) continue; + if (context.Operations.ContainsKey(resultOperation.OperationId)) + { + continue; + } + context.Operations.Add(resultOperation.OperationId, resultOperation); } } diff --git a/src/HotChocolate/OpenApi/tests/HotChocolate.OpenApi.Tests/Controller/PetStoreController.cs b/src/HotChocolate/OpenApi/tests/HotChocolate.OpenApi.Tests/Controller/PetStoreController.cs index 662a7472bc8..299aeb423f7 100644 --- a/src/HotChocolate/OpenApi/tests/HotChocolate.OpenApi.Tests/Controller/PetStoreController.cs +++ b/src/HotChocolate/OpenApi/tests/HotChocolate.OpenApi.Tests/Controller/PetStoreController.cs @@ -32,7 +32,11 @@ public IActionResult DeletePet([FromRoute] [Required] long? id) { var toDelete = _pets.FirstOrDefault(p => p.Id == id); - if (toDelete is null) return BadRequest("Pet not found"); + if (toDelete is null) + { + return BadRequest("Pet not found"); + } + _pets.Remove(toDelete); return Ok(); diff --git a/src/StrawberryShake/Client/src/Core/Serialization/Iso8601Duration.cs b/src/StrawberryShake/Client/src/Core/Serialization/Iso8601Duration.cs index 2e0b4c98346..899fc02bd80 100644 --- a/src/StrawberryShake/Client/src/Core/Serialization/Iso8601Duration.cs +++ b/src/StrawberryShake/Client/src/Core/Serialization/Iso8601Duration.cs @@ -305,10 +305,14 @@ internal static bool TryParse(string s, out TimeSpan? result) // Normalize to nanosecond intervals for (; numDigits > 9; numDigits--) + { value /= 10; + } for (; numDigits < 9; numDigits++) + { value *= 10; + } nanoseconds |= (uint)value; From 4a6fdecc385fd1deecdc0e02ad07e22fef132aab Mon Sep 17 00:00:00 2001 From: AntonC9018 Date: Mon, 15 Jan 2024 15:49:12 +0200 Subject: [PATCH 6/6] Formatting --- .../Helpers/MockHttpRequestData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs b/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs index 47d104c27fc..8e4386d231c 100644 --- a/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs +++ b/src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.IsolatedProcess.Tests/Helpers/MockHttpRequestData.cs @@ -29,7 +29,7 @@ public MockHttpRequestData( Method = requestHttpMethod ?? throw new ArgumentNullException(nameof(requestHttpMethod)); Url = requestUri ?? throw new ArgumentNullException(nameof(requestUri)); - if(claimsIdentities != null) + if (claimsIdentities != null) { Identities = claimsIdentities; }