Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to .NET 9 SDK #26

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -216,16 +218,35 @@ dotnet_naming_style.prefix_underscore.required_prefix = _
# dotnet_naming_rule.<namingRuleTitle>.severity = <value>
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.<namingRuleTitle>.symbols = <symbolTitle>
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.<symbolTitle>.<property> = <value>
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.<namingRuleTitle>.style = <styleTitle>
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

# dotnet_naming_style.<styleTitle>.<property> = <value>
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# dotnet_naming_rule.<namingRuleTitle>.severity = <value>
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.<namingRuleTitle>.symbols = <symbolTitle>
dotnet_naming_rule.constant_fields_should_be_upper_case.symbols = constant_fields_private

# dotnet_naming_symbols.<symbolTitle>.<property> = <value>
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.<namingRuleTitle>.style = <styleTitle>
dotnet_naming_rule.constant_fields_should_be_upper_case.style = upper_case_style

Expand Down Expand Up @@ -257,3 +278,18 @@ dotnet_naming_style.end_in_async_style.required_suffix = Async

# dotnet_naming_rule.<namingRuleTitle>.severity = <value>
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AnalysisMode>Recommended</AnalysisMode>
<AnalysisLevel>9.0-recommended</AnalysisLevel>
<GraphQLVersion>8.0.0</GraphQLVersion>
<GraphQLAspNetCore3Version>6.0.0</GraphQLAspNetCore3Version>
<GraphQLAspNetCore3Version>7.0.0</GraphQLAspNetCore3Version>
<NuGetAuditMode>direct</NuGetAuditMode>
<NoWarn>$(NoWarn);IDE0057;IDE0290</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions GraphQL.DI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,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
Expand Down
22 changes: 4 additions & 18 deletions Sample/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<IndexModel> _logger;

public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}

public void OnGet()
{

}
}
}
2 changes: 1 addition & 1 deletion Sample/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
Expand Down
22 changes: 4 additions & 18 deletions Sample/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
}
}
10 changes: 3 additions & 7 deletions Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -62,8 +59,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseGraphQL<TodoSchema>();
app.UseGraphQLGraphiQL();

app.UseEndpoints(endpoints =>
{
app.UseEndpoints(endpoints => {
endpoints.MapRazorPages();
});
}
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "9.0.100",
"rollForward": "latestMinor"
}
}
8 changes: 3 additions & 5 deletions src/GraphQL.DI/DIGraphAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}<TSource>; 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)}<TSource>; check {nameof(DIGraphAttribute)} attribute marked on '{typeInformation.MemberInfo.DeclaringType?.Name}.{typeInformation.MemberInfo.Name}'.");
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.DI/DIGraphTypeMappingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GraphQL.DI;

internal class DIGraphTypeMappingProvider : IGraphTypeMappingProvider
internal sealed class DIGraphTypeMappingProvider : IGraphTypeMappingProvider
{
private readonly Dictionary<Type, Type> _typeDictionary;

Expand Down
16 changes: 5 additions & 11 deletions src/GraphQL.DI/DIObjectGraphType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using GraphQL.Types;
Expand Down Expand Up @@ -63,12 +62,9 @@ protected override IEnumerable<MemberInfo> GetRegisteredMembers()
protected override LambdaExpression BuildMemberInstanceExpression(MemberInfo memberInfo)
{
// use an explicit type here rather than simply LambdaExpression
Expression<Func<IResolveFieldContext, TDIGraph>> 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<Func<IResolveFieldContext, TDIGraph>>)((IResolveFieldContext context) => MemberInstanceFunc(context));
return func;
}

Expand Down Expand Up @@ -102,12 +98,10 @@ protected override ArgumentInformation GetArgumentInformation<TParameterType>(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();
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.DI/Shane32.GraphQL.DI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Description>
An extension to the graphql-dotnet library to allow easy creation of GraphQL endpoints in a style similar to ASP.Net Core controllers
</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/DIObjectGraphBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Properties
{
private readonly DIObjectGraphBase _graph = new CTest();
private IResolveFieldContext _graphContext => _graph;
private readonly Mock<IResolveFieldContext> _mockContext = new Mock<IResolveFieldContext>(MockBehavior.Strict);
private readonly Mock<IResolveFieldContext> _mockContext = new(MockBehavior.Strict);
private IResolveFieldContext _context => _mockContext.Object;

public Properties()
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/DIObjectGraphTypeTests/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public void IdListType()
public class CIdListType : DIObjectGraphBase<object>
{
[Id]
public static string?[]? Field1() => new[] { "hello" };
public static string?[]? Field1() => ["hello"];
}

[Fact]
Expand Down Expand Up @@ -372,7 +372,7 @@ public void DIGraphListType()
public class CDIGraphListType : DIObjectGraphBase<object>
{
[DIGraph(typeof(CDIGraphType2))]
public static string?[]? Field1() => new[] { "hello" };
public static string?[]? Field1() => ["hello"];
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Execution/GraphQLBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace Execution;

public class GraphQLBuilderTests
{
private readonly Mock<IServiceRegister> _mockServiceRegister = new Mock<IServiceRegister>(MockBehavior.Strict);
private readonly Mock<IGraphQLBuilder> _mockGraphQLBuilder = new Mock<IGraphQLBuilder>(MockBehavior.Strict);
private readonly Mock<IServiceRegister> _mockServiceRegister = new(MockBehavior.Strict);
private readonly Mock<IGraphQLBuilder> _mockGraphQLBuilder = new(MockBehavior.Strict);
private IGraphQLBuilder _graphQLBuilder => _mockGraphQLBuilder.Object;

public GraphQLBuilderTests()
Expand Down
Loading
Loading