diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf3b046..571f0e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,11 +19,11 @@ jobs: pack: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: - dotnet-version: "7.0.x" + dotnet-version: "8.0.x" source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 15cc961..4647456 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -14,12 +14,12 @@ jobs: steps: - name: Checkout source - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: - dotnet-version: "7.0.x" + dotnet-version: "8.0.x" source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index f1fbe50..da54959 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -2,9 +2,6 @@ name: Check formatting on: pull_request: - branches: - - master - - develop paths: - src/** - .github/workflows/** @@ -18,11 +15,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout source - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 357514f..0f9231e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Check github.ref starts with 'refs/tags/' if: ${{ !startsWith(github.ref, 'refs/tags/') }} run: | @@ -28,9 +28,9 @@ jobs: echo version=$version echo "version=$version" >> $GITHUB_ENV - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: - dotnet-version: "7.0.x" + dotnet-version: "8.0.x" 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 93346e9..432f31b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,6 @@ name: Run code tests on: pull_request: - branches: - - master - - develop paths: - src/** - .github/workflows/** @@ -27,22 +24,21 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] graphqlversion: - - 7.0.0 - - 7.1.1 - - 7.2.2 + - 8.0.0 name: ${{ matrix.os }}/${{ matrix.graphqlversion }} runs-on: ${{ matrix.os }} steps: - name: Checkout source - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET SDKs - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 3.1.x 5.0.x 6.0.x 7.0.x + 8.0.x source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/src/BasicSample/BasicSample.csproj b/src/BasicSample/BasicSample.csproj index fb4dc09..05273b9 100644 --- a/src/BasicSample/BasicSample.csproj +++ b/src/BasicSample/BasicSample.csproj @@ -2,7 +2,7 @@ Exe - net7 + net8.0 false @@ -15,9 +15,9 @@ - - - + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 57d3b0f..cb97020 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,8 +1,8 @@ - 7.0.0-preview - 8.0.0 + 8.0.0-preview + 9.0.0 latest Joe McBride MIT diff --git a/src/GraphQL.Authorization.ApiTests/ApiApprovalTests.cs b/src/GraphQL.Authorization.ApiTests/ApiApprovalTests.cs index 083cf74..93bfdd7 100644 --- a/src/GraphQL.Authorization.ApiTests/ApiApprovalTests.cs +++ b/src/GraphQL.Authorization.ApiTests/ApiApprovalTests.cs @@ -20,6 +20,6 @@ public void public_api_should_not_change_unintentionally(Type type) // Note: If the AssemblyName.approved.txt file doesn't match the latest publicApi value, // this call will try to launch a diff tool to help you out but that can fail on // your machine if a diff tool isn't configured/setup. - publicApi.ShouldMatchApproved(options => options.WithFilenameGenerator((_, _, fileType, fileExtension) => $"{type.Assembly.GetName().Name}.{fileType}.{fileExtension}")); + publicApi.ShouldMatchApproved(options => options.NoDiff().WithFilenameGenerator((_, _, fileType, fileExtension) => $"{type.Assembly.GetName().Name}.{fileType}.{fileExtension}")); } } diff --git a/src/GraphQL.Authorization.ApiTests/BomTests.cs b/src/GraphQL.Authorization.ApiTests/BomTests.cs deleted file mode 100644 index b3b5b69..0000000 --- a/src/GraphQL.Authorization.ApiTests/BomTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace GraphQL.Authorization.ApiTests; - -public class BomTests -{ - // https://github.com/graphql-dotnet/graphql-dotnet/pull/3477 - [Fact] - public void Files_Should_Not_Use_BOM() - { - string GetPath([CallerFilePath] string path = "") => path; // \src\GraphQL.ApiTests\BomTests.cs - - var gitRoot = new DirectoryInfo(GetPath()).Parent!.Parent!.Parent!; - // Protection from situations when this test is copied to another repo or the folder structure changed, etc. - if (!File.Exists(Path.Combine(gitRoot.FullName, "src", "GraphQL.Authorization.sln"))) - throw new InvalidOperationException("Unable to find repository root"); - - byte[] buffer = new byte[3]; - int counter = 0; - List files = new(); - - foreach (string file in Directory.EnumerateFiles(gitRoot.FullName, "*.*", SearchOption.AllDirectories)) - { - ++counter; - - if (file.EndsWith(".cs") || file.EndsWith(".csproj")) - { - using var stream = File.OpenRead(file); - - // https://en.wikipedia.org/wiki/Byte_order_mark - if (stream.Read(buffer, 0, 3) == 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF) // EFBBBF - { - files.Add(file); - } - } - } - - Console.WriteLine("Files checked: " + counter); - - if (files.Count > 0) - throw new InvalidOperationException("Remove BOM from files. Files with BOM found:" + Environment.NewLine + string.Join(Environment.NewLine, files)); - } -} diff --git a/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.ApiTests.csproj b/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.ApiTests.csproj index 01901d7..2484755 100644 --- a/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.ApiTests.csproj +++ b/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.ApiTests.csproj @@ -2,7 +2,7 @@ - net7 + net8.0 diff --git a/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt b/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt index b5f295c..64525b3 100644 --- a/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt +++ b/src/GraphQL.Authorization.ApiTests/GraphQL.Authorization.approved.txt @@ -52,10 +52,10 @@ namespace GraphQL.Authorization public System.Collections.Generic.IEnumerable GetPolicies(System.Collections.Generic.IEnumerable policies) { } public GraphQL.Authorization.IAuthorizationPolicy? GetPolicy(string name) { } } - public class AuthorizationValidationRule : GraphQL.Validation.IValidationRule + public class AuthorizationValidationRule : GraphQL.Validation.ValidationRuleBase { public AuthorizationValidationRule(GraphQL.Authorization.IAuthorizationEvaluator evaluator) { } - public System.Threading.Tasks.ValueTask ValidateAsync(GraphQL.Validation.ValidationContext context) { } + public override System.Threading.Tasks.ValueTask GetPreNodeVisitorAsync(GraphQL.Validation.ValidationContext context) { } } public class ClaimAuthorizationRequirement : GraphQL.Authorization.IAuthorizationRequirement { diff --git a/src/GraphQL.Authorization.Tests/AuthorizationValidationRuleTests.cs b/src/GraphQL.Authorization.Tests/AuthorizationValidationRuleTests.cs index 3ddfb5e..b06d13a 100644 --- a/src/GraphQL.Authorization.Tests/AuthorizationValidationRuleTests.cs +++ b/src/GraphQL.Authorization.Tests/AuthorizationValidationRuleTests.cs @@ -424,27 +424,20 @@ public class Author private static ISchema TypedSchema() { var query = new ObjectGraphType(); - query.Field( - "author", - arguments: new QueryArguments(new QueryArgument { Name = "input" }), - resolve: _ => "testing" - ); - - query.Connection() - .Name("posts") + query.Field("author") + .Arguments(new QueryArguments(new QueryArgument { Name = "input" })) + .Resolve(_ => "testing"); + + query.Connection("posts") .AuthorizeWithPolicy("ConnectionPolicy") .Resolve(_ => new Connection()); - query.Field( - "project", - arguments: new QueryArguments(new QueryArgument { Name = "input" }), - resolve: _ => "testing" - ).AuthorizeWithPolicy("AdminPolicy").AuthorizeWithPolicy("ConfidentialPolicy"); + query.Field("project") + .Arguments(new QueryArguments(new QueryArgument { Name = "input" })) + .Resolve(_ => "testing").AuthorizeWithPolicy("AdminPolicy").AuthorizeWithPolicy("ConfidentialPolicy"); - query.Field( - "article", - resolve: _ => null - ); + query.Field("article") + .Resolve(_ => null); return new Schema { Query = query }; } @@ -453,6 +446,7 @@ public class AuthorInputType : InputObjectGraphType { public AuthorInputType() { + Name = "AuthorInputType"; Field(x => x.Name).AuthorizeWithPolicy("FieldPolicy"); } } diff --git a/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj b/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj index 9e28bb8..1123c2c 100644 --- a/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj +++ b/src/GraphQL.Authorization.Tests/GraphQL.Authorization.Tests.csproj @@ -2,15 +2,15 @@ - net7 + net8.0 - net7;net6;net5;netcoreapp3.1 + net8.0;net7.0;net6.0;net5.0;netcoreapp3.1 - 7.0.0 + 8.0.0 diff --git a/src/GraphQL.Authorization.Tests/ValidationTestBase.cs b/src/GraphQL.Authorization.Tests/ValidationTestBase.cs index 0f52355..28c346d 100644 --- a/src/GraphQL.Authorization.Tests/ValidationTestBase.cs +++ b/src/GraphQL.Authorization.Tests/ValidationTestBase.cs @@ -67,7 +67,7 @@ private static IValidationResult Validate(ValidationTestConfig config) Rules = config.Rules, Variables = config.Variables ?? Inputs.Empty, User = config.User - }).GetAwaiter().GetResult().validationResult; + }).GetAwaiter().GetResult(); } internal static ClaimsPrincipal CreatePrincipal(string? authenticationType = null, IDictionary? claims = null) diff --git a/src/GraphQL.Authorization/AuthorizationValidationRule.cs b/src/GraphQL.Authorization/AuthorizationValidationRule.cs index 16aceee..99b49e7 100644 --- a/src/GraphQL.Authorization/AuthorizationValidationRule.cs +++ b/src/GraphQL.Authorization/AuthorizationValidationRule.cs @@ -8,7 +8,7 @@ namespace GraphQL.Authorization; /// GraphQL authorization validation rule which evaluates configured /// (via policies) requirements on schema elements: types, fields, etc. /// -public class AuthorizationValidationRule : IValidationRule +public class AuthorizationValidationRule : ValidationRuleBase { private readonly IAuthorizationEvaluator _evaluator; @@ -22,7 +22,7 @@ public AuthorizationValidationRule(IAuthorizationEvaluator evaluator) } /// - public async ValueTask ValidateAsync(ValidationContext context) + public override async ValueTask GetPreNodeVisitorAsync(ValidationContext context) { var visitor = new Visitor(_evaluator); @@ -113,7 +113,7 @@ public ValueTask LeaveAsync(ASTNode node, ValidationContext context) return default; } - public async ValueTask AuthorizeAsync(ASTNode? node, IProvideMetadata? provider, ValidationContext context) + public async ValueTask AuthorizeAsync(ASTNode? node, IMetadataReader? provider, ValidationContext context) { if (provider == null || !provider.IsAuthorizationRequired()) return; diff --git a/src/GraphQL.Authorization/GraphQL.Authorization.csproj b/src/GraphQL.Authorization/GraphQL.Authorization.csproj index 3db3042..c15b2ed 100644 --- a/src/GraphQL.Authorization/GraphQL.Authorization.csproj +++ b/src/GraphQL.Authorization/GraphQL.Authorization.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Harness/Harness.csproj b/src/Harness/Harness.csproj index 219f5f8..75a27ca 100644 --- a/src/Harness/Harness.csproj +++ b/src/Harness/Harness.csproj @@ -1,7 +1,7 @@ - net7 + net8.0 Example ASP.NET Core project to demonstrate GraphQL.NET Authorization setup false @@ -11,11 +11,10 @@ - - - - - + + + +