From 497c1a3a18946c1c8c4508a2ddb6859b3d2a8e69 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Wed, 11 Dec 2024 18:21:59 -0500 Subject: [PATCH 1/5] Update to .NET 9 SDK --- .editorconfig | 48 +++++++++++++++++--- .github/workflows/build.yml | 4 +- .github/workflows/publish.yml | 4 +- .github/workflows/test.yml | 2 +- Directory.Build.props | 5 +- GraphQL.DI.sln | 1 + global.json | 6 +++ src/GraphQL.DI/DIGraphAttribute.cs | 8 ++-- src/GraphQL.DI/DIGraphTypeMappingProvider.cs | 2 +- src/GraphQL.DI/DIObjectGraphType.cs | 16 ++----- src/GraphQL.DI/Shane32.GraphQL.DI.csproj | 2 +- src/Tests/DIObjectGraphBaseTests.cs | 6 +-- src/Tests/DIObjectGraphTypeTests/Field.cs | 4 +- src/Tests/Execution/GraphQLBuilderTests.cs | 4 +- src/Tests/Tests.csproj | 5 +- 15 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 global.json diff --git a/.editorconfig b/.editorconfig index 571faec..1ba8062 100644 --- a/.editorconfig +++ b/.editorconfig @@ -25,6 +25,7 @@ charset = utf-8 indent_style = space indent_size = 2 trim_trailing_whitespace = true +max_line_length = 140 [*.json] insert_final_newline = false @@ -88,7 +89,7 @@ dotnet_code_quality_unused_parameters = all:warning # C# code style settings - Implicit and explicit types # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#implicit-and-explicit-types -csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_for_built_in_types = true:suggestion csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_elsewhere = true:suggestion @@ -140,8 +141,9 @@ csharp_style_prefer_range_operator = true:warning csharp_style_deconstructed_variable_declaration = true:suggestion csharp_style_pattern_local_over_anonymous_function = true:suggestion csharp_using_directive_placement = outside_namespace:warning +csharp_style_namespace_declarations = file_scoped:warning csharp_prefer_static_local_function = true:suggestion -csharp_prefer_simple_using_statement = false:suggestion +csharp_prefer_simple_using_statement = true:warning csharp_style_prefer_switch_expression = true:suggestion # .NET formatting settings - Organize using directives @@ -151,7 +153,7 @@ dotnet_separate_import_directive_groups = false # C# formatting settings - New-line options # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019#new-line-options -csharp_new_line_before_open_brace = types, methods +csharp_new_line_before_open_brace = types, methods, properties csharp_new_line_before_else = false csharp_new_line_before_catch = false csharp_new_line_before_finally = false @@ -216,16 +218,35 @@ dotnet_naming_style.prefix_underscore.required_prefix = _ # dotnet_naming_rule..severity = dotnet_naming_rule.private_fields_with_underscore.severity = warning -########## name all constant fields using UPPER_CASE ########## +########## name all public constant fields using PascalCase ########## # https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019 # dotnet_naming_rule..symbols = -dotnet_naming_rule.constant_fields_should_be_upper_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields # dotnet_naming_symbols.. = dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields.applicable_accessibilities = public dotnet_naming_symbols.constant_fields.required_modifiers = const +# dotnet_naming_rule..style = +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style + +# dotnet_naming_style.. = +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# dotnet_naming_rule..severity = +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning + +########## name all other constant fields using UPPER_CASE ########## +# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019 +# dotnet_naming_rule..symbols = +dotnet_naming_rule.constant_fields_should_be_upper_case.symbols = constant_fields_private + +# dotnet_naming_symbols.. = +dotnet_naming_symbols.constant_fields_private.applicable_kinds = field +dotnet_naming_symbols.constant_fields_private.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields_private.required_modifiers = const + # dotnet_naming_rule..style = dotnet_naming_rule.constant_fields_should_be_upper_case.style = upper_case_style @@ -257,3 +278,18 @@ dotnet_naming_style.end_in_async_style.required_suffix = Async # dotnet_naming_rule..severity = dotnet_naming_rule.async_methods_end_in_async.severity = warning + +# ignore underscores in names +dotnet_diagnostic.CA1707.severity = none + +# IDE0005: Remove unnecessary using directives +dotnet_diagnostic.IDE0005.severity = suggestion + +# IDE0058: Remove unnecessary expression value +dotnet_diagnostic.IDE0058.severity = none + +# IDE0008: Use explicit type +dotnet_diagnostic.IDE0008.severity = none + +# IDE0290: Use primary constructor +dotnet_diagnostic.IDE0290.severity = none diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 01cabe8..5de166c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use .NET Core 6.0 SDK + - name: Use .NET Core SDK uses: actions/setup-dotnet@v4 with: - dotnet-version: '6.0.x' + global-json-file: global.json source-url: https://nuget.pkg.github.com/Shane32/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 966a64e..e797380 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,10 +23,10 @@ jobs: version="${github_ref:10}" echo version=$version echo "version=$version" >> $GITHUB_ENV - - name: Use .NET Core 6.0 SDK + - name: Use .NET Core SDK uses: actions/setup-dotnet@v4 with: - dotnet-version: '6.0.x' + global-json-file: global.json source-url: https://api.nuget.org/v3/index.json env: NUGET_AUTH_TOKEN: ${{secrets.NUGET_AUTH_TOKEN}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 578dfb8..2827a2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: Use .NET Core SDK uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.x + global-json-file: global.json source-url: https://nuget.pkg.github.com/Shane32/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/Directory.Build.props b/Directory.Build.props index 3e4a590..a2c5d2d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,10 +21,11 @@ enable false README.md - Recommended + 9.0-recommended 8.0.0 - 6.0.0 + 7.0.0 direct + $(NoWarn);IDE0057;IDE0290 diff --git a/GraphQL.DI.sln b/GraphQL.DI.sln index 4f0c101..fee2fc0 100644 --- a/GraphQL.DI.sln +++ b/GraphQL.DI.sln @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution items", "Solution .editorconfig = .editorconfig .gitignore = .gitignore Directory.Build.props = Directory.Build.props + global.json = global.json LICENSE = LICENSE logo.64x64.png = logo.64x64.png logo.jpg = logo.jpg diff --git a/global.json b/global.json new file mode 100644 index 0000000..f15a959 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "9.0.100", + "rollForward": "latestMinor" + } +} \ No newline at end of file diff --git a/src/GraphQL.DI/DIGraphAttribute.cs b/src/GraphQL.DI/DIGraphAttribute.cs index f3f012b..7f2db39 100644 --- a/src/GraphQL.DI/DIGraphAttribute.cs +++ b/src/GraphQL.DI/DIGraphAttribute.cs @@ -24,11 +24,9 @@ public override void Modify(TypeInformation typeInformation) if (typeInformation.IsInputType) return; var iface = GraphBaseType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IDIObjectGraphBase<>)); - if (iface != null) { - typeInformation.GraphType = typeof(DIObjectGraphType<,>).MakeGenericType(GraphBaseType, iface.GetGenericArguments()[0]); - } else { - throw new InvalidOperationException($"Type '{GraphBaseType.Name}' does not implement {nameof(IDIObjectGraphBase)}; check {nameof(DIGraphAttribute)} attribute marked on '{typeInformation.MemberInfo.DeclaringType.Name}.{typeInformation.MemberInfo.Name}'."); - } + typeInformation.GraphType = iface != null + ? typeof(DIObjectGraphType<,>).MakeGenericType(GraphBaseType, iface.GetGenericArguments()[0]) + : throw new InvalidOperationException($"Type '{GraphBaseType.Name}' does not implement {nameof(IDIObjectGraphBase)}; check {nameof(DIGraphAttribute)} attribute marked on '{typeInformation.MemberInfo.DeclaringType?.Name}.{typeInformation.MemberInfo.Name}'."); } /// diff --git a/src/GraphQL.DI/DIGraphTypeMappingProvider.cs b/src/GraphQL.DI/DIGraphTypeMappingProvider.cs index 9c6a2d1..ab27334 100644 --- a/src/GraphQL.DI/DIGraphTypeMappingProvider.cs +++ b/src/GraphQL.DI/DIGraphTypeMappingProvider.cs @@ -2,7 +2,7 @@ namespace GraphQL.DI; -internal class DIGraphTypeMappingProvider : IGraphTypeMappingProvider +internal sealed class DIGraphTypeMappingProvider : IGraphTypeMappingProvider { private readonly Dictionary _typeDictionary; diff --git a/src/GraphQL.DI/DIObjectGraphType.cs b/src/GraphQL.DI/DIObjectGraphType.cs index a156165..be8077a 100644 --- a/src/GraphQL.DI/DIObjectGraphType.cs +++ b/src/GraphQL.DI/DIObjectGraphType.cs @@ -1,4 +1,3 @@ -using System.Diagnostics; using System.Linq.Expressions; using System.Reflection; using GraphQL.Types; @@ -63,12 +62,9 @@ protected override IEnumerable GetRegisteredMembers() protected override LambdaExpression BuildMemberInstanceExpression(MemberInfo memberInfo) { // use an explicit type here rather than simply LambdaExpression - Expression> func; - if (typeof(IDisposable).IsAssignableFrom(typeof(TDIGraph))) { - func = (IResolveFieldContext context) => MemberInstanceDisposableFunc(context); - } else { - func = (IResolveFieldContext context) => MemberInstanceFunc(context); - } + var func = typeof(IDisposable).IsAssignableFrom(typeof(TDIGraph)) + ? ((IResolveFieldContext context) => MemberInstanceDisposableFunc(context)) + : (Expression>)((IResolveFieldContext context) => MemberInstanceFunc(context)); return func; } @@ -102,12 +98,10 @@ protected override ArgumentInformation GetArgumentInformation(Fi { var typeInformation = GetTypeInformation(parameterInfo); var argumentInfo = new ArgumentInformation(parameterInfo, typeof(TSource), fieldType, typeInformation); - if (argumentInfo.ParameterInfo.ParameterType == typeof(IServiceProvider)) - { + if (argumentInfo.ParameterInfo.ParameterType == typeof(IServiceProvider)) { argumentInfo.SetDelegate(context => context.RequestServices ?? throw new MissingRequestServicesException()); } - if (argumentInfo.ParameterInfo.Name == "source" && argumentInfo.ParameterInfo.ParameterType == typeof(TSource)) - { + if (argumentInfo.ParameterInfo.Name == "source" && argumentInfo.ParameterInfo.ParameterType == typeof(TSource)) { argumentInfo.SetDelegate(context => (TSource?)context.Source); } argumentInfo.ApplyAttributes(); diff --git a/src/GraphQL.DI/Shane32.GraphQL.DI.csproj b/src/GraphQL.DI/Shane32.GraphQL.DI.csproj index 1a4363c..4de3ca7 100644 --- a/src/GraphQL.DI/Shane32.GraphQL.DI.csproj +++ b/src/GraphQL.DI/Shane32.GraphQL.DI.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0 An extension to the graphql-dotnet library to allow easy creation of GraphQL endpoints in a style similar to ASP.Net Core controllers diff --git a/src/Tests/DIObjectGraphBaseTests.cs b/src/Tests/DIObjectGraphBaseTests.cs index 335445b..2dae334 100644 --- a/src/Tests/DIObjectGraphBaseTests.cs +++ b/src/Tests/DIObjectGraphBaseTests.cs @@ -7,7 +7,7 @@ public class Properties { private readonly DIObjectGraphBase _graph = new CTest(); private IResolveFieldContext _graphContext => _graph; - private readonly Mock _mockContext = new Mock(MockBehavior.Strict); + private readonly Mock _mockContext = new(MockBehavior.Strict); private IResolveFieldContext _context => _mockContext.Object; public Properties() @@ -223,11 +223,11 @@ public void RFC_ArrayPool() _graphContext.ArrayPool.ShouldBe(obj); } - private class CTest : DIObjectGraphBase + private sealed class CTest : DIObjectGraphBase { } - private class CTest : DIObjectGraphBase + private sealed class CTest : DIObjectGraphBase { } } diff --git a/src/Tests/DIObjectGraphTypeTests/Field.cs b/src/Tests/DIObjectGraphTypeTests/Field.cs index a7bcb0a..4186d89 100644 --- a/src/Tests/DIObjectGraphTypeTests/Field.cs +++ b/src/Tests/DIObjectGraphTypeTests/Field.cs @@ -325,7 +325,7 @@ public void IdListType() public class CIdListType : DIObjectGraphBase { [Id] - public static string?[]? Field1() => new[] { "hello" }; + public static string?[]? Field1() => ["hello"]; } [Fact] @@ -372,7 +372,7 @@ public void DIGraphListType() public class CDIGraphListType : DIObjectGraphBase { [DIGraph(typeof(CDIGraphType2))] - public static string?[]? Field1() => new[] { "hello" }; + public static string?[]? Field1() => ["hello"]; } [Fact] diff --git a/src/Tests/Execution/GraphQLBuilderTests.cs b/src/Tests/Execution/GraphQLBuilderTests.cs index 284e671..e51c22d 100644 --- a/src/Tests/Execution/GraphQLBuilderTests.cs +++ b/src/Tests/Execution/GraphQLBuilderTests.cs @@ -4,8 +4,8 @@ namespace Execution; public class GraphQLBuilderTests { - private readonly Mock _mockServiceRegister = new Mock(MockBehavior.Strict); - private readonly Mock _mockGraphQLBuilder = new Mock(MockBehavior.Strict); + private readonly Mock _mockServiceRegister = new(MockBehavior.Strict); + private readonly Mock _mockGraphQLBuilder = new(MockBehavior.Strict); private IGraphQLBuilder _graphQLBuilder => _mockGraphQLBuilder.Object; public GraphQLBuilderTests() diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 41d66ab..df81dcd 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -1,8 +1,9 @@ - + net6.0 - $(NoWarn);1701;1702;1591;IDE1006;IDE0060;0618;CA1707;CA1822;CS1591 + + $(NoWarn);1701;1702;1591;IDE1006;IDE0060;0618;CA1707;CA1822;CS1591;CA1861;IDE0022;IDE0021;IDE0028;CA1852 From b7dedc49d459aee3a20ea637151bb2123f318331 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Wed, 11 Dec 2024 18:23:38 -0500 Subject: [PATCH 2/5] update --- src/Tests/DIObjectGraphBaseTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/DIObjectGraphBaseTests.cs b/src/Tests/DIObjectGraphBaseTests.cs index 2dae334..463c7dd 100644 --- a/src/Tests/DIObjectGraphBaseTests.cs +++ b/src/Tests/DIObjectGraphBaseTests.cs @@ -223,11 +223,11 @@ public void RFC_ArrayPool() _graphContext.ArrayPool.ShouldBe(obj); } - private sealed class CTest : DIObjectGraphBase + private class CTest : DIObjectGraphBase { } - private sealed class CTest : DIObjectGraphBase + private class CTest : DIObjectGraphBase { } } From 1a80ac5794eaf479597eeba9ac39d209d89e6419 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Wed, 11 Dec 2024 18:26:18 -0500 Subject: [PATCH 3/5] add formatting check --- .github/workflows/format.yml | 24 ++++++++++++++++++++++++ GraphQL.DI.sln | 1 + global.json | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..75a64c6 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,24 @@ +name: Check formatting + +# ==== NOTE: do not rename this yml file or the run_number will be reset ==== + +on: + pull_request: + +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use .NET Core SDK + uses: actions/setup-dotnet@v4 + with: + global-json-file: global.json + source-url: https://nuget.pkg.github.com/Shane32/index.json + env: + NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + - name: Install dependencies + run: dotnet restore + - name: Check formatting + run: | + dotnet format --no-restore --verify-no-changes --severity error || (echo "Run 'dotnet format' to fix issues" && exit 1) diff --git a/GraphQL.DI.sln b/GraphQL.DI.sln index fee2fc0..1242a7f 100644 --- a/GraphQL.DI.sln +++ b/GraphQL.DI.sln @@ -24,6 +24,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{7432A0AF-9346-41D7-9DA9-D7EFEAF1A401}" ProjectSection(SolutionItems) = preProject .github\workflows\build.yml = .github\workflows\build.yml + .github\workflows\format.yml = .github\workflows\format.yml .github\workflows\publish.yml = .github\workflows\publish.yml .github\workflows\test.yml = .github\workflows\test.yml EndProjectSection diff --git a/global.json b/global.json index f15a959..2bc13e8 100644 --- a/global.json +++ b/global.json @@ -3,4 +3,4 @@ "version": "9.0.100", "rollForward": "latestMinor" } -} \ No newline at end of file +} From 394e3d52a17887529b77c26f5172f2fbde80eb8a Mon Sep 17 00:00:00 2001 From: Shane32 Date: Wed, 11 Dec 2024 18:27:56 -0500 Subject: [PATCH 4/5] formatting --- Sample/Pages/Privacy.cshtml | 2 +- Sample/Startup.cs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Sample/Pages/Privacy.cshtml b/Sample/Pages/Privacy.cshtml index 46ba966..8c3afc0 100644 --- a/Sample/Pages/Privacy.cshtml +++ b/Sample/Pages/Privacy.cshtml @@ -1,4 +1,4 @@ -@page +@page @model PrivacyModel @{ ViewData["Title"] = "Privacy Policy"; diff --git a/Sample/Startup.cs b/Sample/Startup.cs index dc04385..fc5d018 100644 --- a/Sample/Startup.cs +++ b/Sample/Startup.cs @@ -44,12 +44,9 @@ public void ConfigureServices(IServiceCollection services) // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (env.IsDevelopment()) - { + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - } - else - { + } else { app.UseExceptionHandler("/Error"); } @@ -62,8 +59,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseGraphQL(); app.UseGraphQLGraphiQL(); - app.UseEndpoints(endpoints => - { + app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } From d0cf3e570892fe458a65f19ae787695eccdeb2a6 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Wed, 11 Dec 2024 18:31:33 -0500 Subject: [PATCH 5/5] update --- Sample/Pages/Index.cshtml.cs | 22 ++++------------------ Sample/Pages/Privacy.cshtml.cs | 22 ++++------------------ 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/Sample/Pages/Index.cshtml.cs b/Sample/Pages/Index.cshtml.cs index 4eeddfd..42029e4 100644 --- a/Sample/Pages/Index.cshtml.cs +++ b/Sample/Pages/Index.cshtml.cs @@ -1,25 +1,11 @@ -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace Sample.Pages +namespace Sample.Pages; + +public class IndexModel : PageModel { - public class IndexModel : PageModel + public void OnGet() { - private readonly ILogger _logger; - - public IndexModel(ILogger logger) - { - _logger = logger; - } - - public void OnGet() - { - } } } diff --git a/Sample/Pages/Privacy.cshtml.cs b/Sample/Pages/Privacy.cshtml.cs index 7b2a439..9383e44 100644 --- a/Sample/Pages/Privacy.cshtml.cs +++ b/Sample/Pages/Privacy.cshtml.cs @@ -1,24 +1,10 @@ -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace Sample.Pages +namespace Sample.Pages; + +public class PrivacyModel : PageModel { - public class PrivacyModel : PageModel + public void OnGet() { - private readonly ILogger _logger; - - public PrivacyModel(ILogger logger) - { - _logger = logger; - } - - public void OnGet() - { - } } }