diff --git a/.github/workflows/publish-dev.yml b/.github/workflows/publish-dev.yml index 4f77a67..0c5eea4 100644 --- a/.github/workflows/publish-dev.yml +++ b/.github/workflows/publish-dev.yml @@ -3,20 +3,20 @@ name: Publish dev on: push: branches: - - publish-dev + - publish-dev/** jobs: build: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Setup .NET Core 6.0 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: dotnet-version: 6.0.x - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: dotnet-version: 3.1.x - name: Install dependencies diff --git a/Directory.Build.props b/Directory.Build.props index 509102f..0c08ad7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,9 +9,10 @@ true enable true + true - 7 + 8 0 $(BuildNumber) 0 diff --git a/Mindbox.ExceptionsHandling.Abstractions/Mindbox.ExceptionsHandling.Abstractions.csproj b/Mindbox.ExceptionsHandling.Abstractions/Mindbox.ExceptionsHandling.Abstractions.csproj index 32ce8f4..24d8036 100644 --- a/Mindbox.ExceptionsHandling.Abstractions/Mindbox.ExceptionsHandling.Abstractions.csproj +++ b/Mindbox.ExceptionsHandling.Abstractions/Mindbox.ExceptionsHandling.Abstractions.csproj @@ -4,7 +4,7 @@ Mindbox.ExceptionsHandling - - + + \ No newline at end of file diff --git a/Mindbox.ExceptionsHandling.GraphQL/ConfigurationExtensions.cs b/Mindbox.ExceptionsHandling.GraphQL/ConfigurationExtensions.cs index 67fbf71..d1472a1 100644 --- a/Mindbox.ExceptionsHandling.GraphQL/ConfigurationExtensions.cs +++ b/Mindbox.ExceptionsHandling.GraphQL/ConfigurationExtensions.cs @@ -10,5 +10,5 @@ public static class ConfigurationExtensions public static IServiceCollection AddGraphQLErrorHandling(this IServiceCollection services) => services .AddErrorFilter() - .AddHttpResultSerializer(); + .AddHttpResponseFormatter(); } \ No newline at end of file diff --git a/Mindbox.ExceptionsHandling.GraphQL/GraphQLHttpAgnosticResultSerializer.cs b/Mindbox.ExceptionsHandling.GraphQL/GraphQLHttpAgnosticResultFormatter.cs similarity index 50% rename from Mindbox.ExceptionsHandling.GraphQL/GraphQLHttpAgnosticResultSerializer.cs rename to Mindbox.ExceptionsHandling.GraphQL/GraphQLHttpAgnosticResultFormatter.cs index 2b2f073..8f2879a 100644 --- a/Mindbox.ExceptionsHandling.GraphQL/GraphQLHttpAgnosticResultSerializer.cs +++ b/Mindbox.ExceptionsHandling.GraphQL/GraphQLHttpAgnosticResultFormatter.cs @@ -5,15 +5,17 @@ namespace Mindbox.ExceptionsHandling.GraphQL; -public class GraphQLHttpAgnosticResultSerializer : DefaultHttpResultSerializer +public class GraphQLHttpAgnosticResultFormatter : DefaultHttpResponseFormatter { - public override HttpStatusCode GetStatusCode(IExecutionResult result) + protected override HttpStatusCode OnDetermineStatusCode( + IQueryResult result, + FormatInfo format, + HttpStatusCode? proposedStatusCode) { return result switch { + // This is required for our frontend QueryResult => HttpStatusCode.OK, - DeferredQueryResult => HttpStatusCode.OK, - BatchQueryResult => HttpStatusCode.OK, _ => HttpStatusCode.InternalServerError }; } diff --git a/Mindbox.ExceptionsHandling.GraphQL/Mindbox.ExceptionsHandling.GraphQL.csproj b/Mindbox.ExceptionsHandling.GraphQL/Mindbox.ExceptionsHandling.GraphQL.csproj index b9d5d56..099107a 100644 --- a/Mindbox.ExceptionsHandling.GraphQL/Mindbox.ExceptionsHandling.GraphQL.csproj +++ b/Mindbox.ExceptionsHandling.GraphQL/Mindbox.ExceptionsHandling.GraphQL.csproj @@ -3,8 +3,8 @@ net6.0 - - + + diff --git a/Mindbox.ExceptionsHandling.Tests/GraphQLHttpAgnosticResultSerializerTests.cs b/Mindbox.ExceptionsHandling.Tests/GraphQLHttpAgnosticResultSerializerTests.cs deleted file mode 100644 index 7450c75..0000000 --- a/Mindbox.ExceptionsHandling.Tests/GraphQLHttpAgnosticResultSerializerTests.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Net; -using System.Threading.Tasks; -using HotChocolate.Execution; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Mindbox.ExceptionsHandling.GraphQL; -using Moq; - -namespace Mindbox.ExceptionsHandling.Tests; - -[TestClass] -public class GraphQLHttpAgnosticResultSerializerTests -{ - private readonly GraphQLHttpAgnosticResultSerializer _serializer = new(); - - [TestMethod] - public void GetStatusCode_QueryResult_OK() - { - var executionResult = new QueryResult(new Dictionary(), null); - - var statusCode = _serializer.GetStatusCode(executionResult); - - Assert.AreEqual(HttpStatusCode.OK, statusCode); - } - - [TestMethod] - public void GetStatusCode_DeferredQueryResult_OK() - { - var executionResult = new DeferredQueryResult( - new QueryResult(new Dictionary(), null), - EmptyAsyncEnumerable()); - - var statusCode = _serializer.GetStatusCode(executionResult); - - Assert.AreEqual(HttpStatusCode.OK, statusCode); - } - - [TestMethod] - public void GetStatusCode_BatchQueryResultQueryResult_OK() - { - var executionResult = new BatchQueryResult(EmptyAsyncEnumerable, null); - - var statusCode = _serializer.GetStatusCode(executionResult); - - Assert.AreEqual(HttpStatusCode.OK, statusCode); - } - - [TestMethod] - public void GetStatusCode_Other_InternalServerError() - { - var executionResult = new Mock().Object; - - var statusCode = _serializer.GetStatusCode(executionResult); - - Assert.AreEqual(HttpStatusCode.InternalServerError, statusCode); - } - - private static async IAsyncEnumerable EmptyAsyncEnumerable() - { - await Task.CompletedTask; - yield break; - } -} \ No newline at end of file diff --git a/Mindbox.ExceptionsHandling.Tests/Mindbox.ExceptionsHandling.Tests.csproj b/Mindbox.ExceptionsHandling.Tests/Mindbox.ExceptionsHandling.Tests.csproj index 2a15431..fd06e28 100644 --- a/Mindbox.ExceptionsHandling.Tests/Mindbox.ExceptionsHandling.Tests.csproj +++ b/Mindbox.ExceptionsHandling.Tests/Mindbox.ExceptionsHandling.Tests.csproj @@ -4,12 +4,12 @@ net6.0 - - + + - - - + + + diff --git a/Mindbox.ExceptionsHandling/Mindbox.ExceptionsHandling.csproj b/Mindbox.ExceptionsHandling/Mindbox.ExceptionsHandling.csproj index d2963dc..6c337ce 100644 --- a/Mindbox.ExceptionsHandling/Mindbox.ExceptionsHandling.csproj +++ b/Mindbox.ExceptionsHandling/Mindbox.ExceptionsHandling.csproj @@ -5,7 +5,7 @@ - +