From 6b40f905e2317cd04049d6e1522d711c892f0964 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Wed, 22 Nov 2023 17:23:00 +0100 Subject: [PATCH 1/9] extend test to cover issue --- .../ConsistencyTests.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs b/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs index 200c0acf..0a199b2c 100644 --- a/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs +++ b/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs @@ -9,10 +9,8 @@ namespace GraphQL.Client.Serializer.Tests; public class ConsistencyTests { - [Fact] - public void MapConvertersShouldBehaveConsistent() - { - const string json = @"{ + [Theory] + [InlineData(@"{ ""array"": [ ""some stuff"", ""something else"" @@ -27,7 +25,26 @@ public void MapConvertersShouldBehaveConsistent() {""number"": 1234.567}, {""number"": 567.8} ] - }"; + }")] + [InlineData("null")] + public void MapConvertersShouldBehaveConsistent(string json) + { + //const string json = @"{ + // ""array"": [ + // ""some stuff"", + // ""something else"" + // ], + // ""string"": ""this is a string"", + // ""boolean"": true, + // ""number"": 1234.567, + // ""nested object"": { + // ""prop1"": false + // }, + // ""arrayOfObjects"": [ + // {""number"": 1234.567}, + // {""number"": 567.8} + // ] + // }"; var newtonsoftSerializer = new NewtonsoftJsonSerializer(); var systemTextJsonSerializer = new SystemTextJsonSerializer(); @@ -45,6 +62,20 @@ public void MapConvertersShouldBehaveConsistent() .RespectingRuntimeTypes()); } + /// + /// Regression test for https://github.com/graphql-dotnet/graphql-client/issues/601 + /// + [Fact] + public void MapConvertersShouldBeAbleToDeserializeNullValues() + { + var newtonsoftSerializer = new NewtonsoftJsonSerializer(); + var systemTextJsonSerializer = new SystemTextJsonSerializer(); + string json = "null"; + + JsonConvert.DeserializeObject(json, newtonsoftSerializer.JsonSerializerSettings).Should().BeNull(); + System.Text.Json.JsonSerializer.Deserialize(json, systemTextJsonSerializer.Options).Should().BeNull(); + } + private void CompareMaps(Dictionary first, Dictionary second) { foreach (var keyValuePair in first) From 098da89cd82cc8e42eea886bd7d8f07d25bb3a55 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Wed, 22 Nov 2023 17:27:43 +0100 Subject: [PATCH 2/9] fix test --- .../ConsistencyTests.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs b/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs index 0a199b2c..7a3f8f55 100644 --- a/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs +++ b/tests/GraphQL.Client.Serializer.Tests/ConsistencyTests.cs @@ -76,16 +76,19 @@ public void MapConvertersShouldBeAbleToDeserializeNullValues() System.Text.Json.JsonSerializer.Deserialize(json, systemTextJsonSerializer.Options).Should().BeNull(); } - private void CompareMaps(Dictionary first, Dictionary second) + private void CompareMaps(Dictionary? first, Dictionary? second) { - foreach (var keyValuePair in first) - { - second.Should().ContainKey(keyValuePair.Key); - second[keyValuePair.Key].Should().BeOfType(keyValuePair.Value.GetType()); - if (keyValuePair.Value is Dictionary map) - CompareMaps(map, (Dictionary)second[keyValuePair.Key]); - else - keyValuePair.Value.Should().BeEquivalentTo(second[keyValuePair.Key]); - } + if (first is null) + second.Should().BeNull(); + else + foreach (var keyValuePair in first) + { + second.Should().ContainKey(keyValuePair.Key); + second[keyValuePair.Key].Should().BeOfType(keyValuePair.Value.GetType()); + if (keyValuePair.Value is Dictionary map) + CompareMaps(map, (Dictionary)second[keyValuePair.Key]); + else + keyValuePair.Value.Should().BeEquivalentTo(second[keyValuePair.Key]); + } } } From d53583dd168f299582aaf7a6ab1bf9fe12ef1588 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Wed, 22 Nov 2023 17:27:54 +0100 Subject: [PATCH 3/9] fix newtonsoft mapconverter --- .../MapConverter.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GraphQL.Client.Serializer.Newtonsoft/MapConverter.cs b/src/GraphQL.Client.Serializer.Newtonsoft/MapConverter.cs index 90b22ed8..5bc53686 100644 --- a/src/GraphQL.Client.Serializer.Newtonsoft/MapConverter.cs +++ b/src/GraphQL.Client.Serializer.Newtonsoft/MapConverter.cs @@ -9,15 +9,15 @@ public override void WriteJson(JsonWriter writer, Map value, JsonSerializer seri throw new NotImplementedException( "This converter currently is only intended to be used to read a JSON object into a strongly-typed representation."); - public override Map ReadJson(JsonReader reader, Type objectType, Map existingValue, bool hasExistingValue, JsonSerializer serializer) + public override Map? ReadJson(JsonReader reader, Type objectType, Map existingValue, bool hasExistingValue, JsonSerializer serializer) { var rootToken = JToken.ReadFrom(reader); - if (rootToken is JObject) + return rootToken.Type switch { - return (Map)ReadDictionary(rootToken, new Map()); - } - else - throw new ArgumentException("This converter can only parse when the root element is a JSON Object."); + JTokenType.Object => (Map)ReadDictionary(rootToken, new Map()), + JTokenType.Null => null, + _ => throw new ArgumentException("This converter can only parse when the root element is a JSON Object.") + }; } private object? ReadToken(JToken? token) => From 3e83195f24b0261537037a1aabdbf03f8391bf6e Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 23 Nov 2023 07:58:02 +0100 Subject: [PATCH 4/9] update gitversion --- Directory.Build.targets | 8 ++++---- dotnet-tools.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index a75e6500..c97c17d4 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -6,7 +6,7 @@ true - + $(NoWarn);1591 @@ -34,9 +34,9 @@ - + all - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers diff --git a/dotnet-tools.json b/dotnet-tools.json index 7254cc09..e5146732 100644 --- a/dotnet-tools.json +++ b/dotnet-tools.json @@ -8,7 +8,7 @@ ] }, "gitversion.tool": { - "version": "5.10.3", + "version": "5.12.0", "commands": [ "dotnet-gitversion" ] From 00b438d5fd616e130346f707f6e100b9ba335218 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 23 Nov 2023 08:08:51 +0100 Subject: [PATCH 5/9] Try to fix breaking change regarding implicit using uf System.Net.Http --- src/GraphQL.Client/GraphQLHttpClient.cs | 4 ++++ src/GraphQL.Client/GraphQLHttpClientOptions.cs | 4 ++++ src/GraphQL.Client/GraphQLHttpRequest.cs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/GraphQL.Client/GraphQLHttpClient.cs b/src/GraphQL.Client/GraphQLHttpClient.cs index 7ffea50b..dd03334a 100644 --- a/src/GraphQL.Client/GraphQLHttpClient.cs +++ b/src/GraphQL.Client/GraphQLHttpClient.cs @@ -1,4 +1,8 @@ using System.Diagnostics; +#pragma warning disable IDE0005 +// see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/implicit-global-using-netfx +using System.Net.Http; +#pragma warning restore IDE0005 using GraphQL.Client.Abstractions; using GraphQL.Client.Abstractions.Websocket; using GraphQL.Client.Http.Websocket; diff --git a/src/GraphQL.Client/GraphQLHttpClientOptions.cs b/src/GraphQL.Client/GraphQLHttpClientOptions.cs index 169260f0..6c3b30d1 100644 --- a/src/GraphQL.Client/GraphQLHttpClientOptions.cs +++ b/src/GraphQL.Client/GraphQLHttpClientOptions.cs @@ -1,4 +1,8 @@ using System.Net; +#pragma warning disable IDE0005 +// see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/implicit-global-using-netfx +using System.Net.Http; +#pragma warning restore IDE0005 using System.Net.Http.Headers; using System.Net.WebSockets; using GraphQL.Client.Http.Websocket; diff --git a/src/GraphQL.Client/GraphQLHttpRequest.cs b/src/GraphQL.Client/GraphQLHttpRequest.cs index d03b9f8e..986f1dd5 100644 --- a/src/GraphQL.Client/GraphQLHttpRequest.cs +++ b/src/GraphQL.Client/GraphQLHttpRequest.cs @@ -1,3 +1,7 @@ +#pragma warning disable IDE0005 +// see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/implicit-global-using-netfx +using System.Net.Http; +#pragma warning restore IDE0005 using System.Net.Http.Headers; using System.Text; using GraphQL.Client.Abstractions; From e9f8578f546aa6d03a223e1389a526f46cac159d Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 23 Nov 2023 08:20:17 +0100 Subject: [PATCH 6/9] update sourcelink package to v 8.0.0 --- Directory.Build.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index c97c17d4..f731aa6c 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -33,7 +33,7 @@ - + all runtime; build; native; contentfiles; analyzers From 32fa2a9c94a587e558922554df813c3980c7c372 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 23 Nov 2023 08:22:25 +0100 Subject: [PATCH 7/9] rm package ref to sourcelink --- Directory.Build.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index f731aa6c..f09b31ba 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -33,7 +33,7 @@ - + all runtime; build; native; contentfiles; analyzers From 70ee7c2b77620d2efe74bbded530c4c95c4da7dd Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 23 Nov 2023 08:24:13 +0100 Subject: [PATCH 8/9] add using System.Net.Http to GraphQLHttpWebSocket --- src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs b/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs index 32925567..4be55bc7 100644 --- a/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs +++ b/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs @@ -1,4 +1,8 @@ using System.Diagnostics; +#pragma warning disable IDE0005 +// see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/implicit-global-using-netfx +using System.Net.Http; +#pragma warning restore IDE0005 using System.Net.WebSockets; using System.Reactive; using System.Reactive.Disposables; From 67ccc9c2952dd2226878297020e6cc91be8a2c3e Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 23 Nov 2023 09:01:38 +0100 Subject: [PATCH 9/9] upgrade net7 projects to net8 --- examples/GraphQL.Client.Example/GraphQL.Client.Example.csproj | 2 +- .../GraphQL.Client.Serializer.Tests.csproj | 2 +- .../GraphQL.Client.Tests.Common.csproj | 2 +- .../GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj | 2 +- tests/GraphQL.Primitives.Tests/GraphQL.Primitives.Tests.csproj | 2 +- tests/GraphQL.Server.Test/GraphQL.Server.Test.csproj | 2 +- tests/IntegrationTestServer/IntegrationTestServer.csproj | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/GraphQL.Client.Example/GraphQL.Client.Example.csproj b/examples/GraphQL.Client.Example/GraphQL.Client.Example.csproj index 28c2c457..07866dfc 100644 --- a/examples/GraphQL.Client.Example/GraphQL.Client.Example.csproj +++ b/examples/GraphQL.Client.Example/GraphQL.Client.Example.csproj @@ -2,7 +2,7 @@ Exe - net7 + net8 false diff --git a/tests/GraphQL.Client.Serializer.Tests/GraphQL.Client.Serializer.Tests.csproj b/tests/GraphQL.Client.Serializer.Tests/GraphQL.Client.Serializer.Tests.csproj index ed2da1ab..7273de9a 100644 --- a/tests/GraphQL.Client.Serializer.Tests/GraphQL.Client.Serializer.Tests.csproj +++ b/tests/GraphQL.Client.Serializer.Tests/GraphQL.Client.Serializer.Tests.csproj @@ -3,7 +3,7 @@ - net7 + net8 diff --git a/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj b/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj index 138f4c67..460fe724 100644 --- a/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj +++ b/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 false diff --git a/tests/GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj b/tests/GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj index d6f082fe..fdc033fa 100644 --- a/tests/GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj +++ b/tests/GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj @@ -3,7 +3,7 @@ - net7 + net8 diff --git a/tests/GraphQL.Primitives.Tests/GraphQL.Primitives.Tests.csproj b/tests/GraphQL.Primitives.Tests/GraphQL.Primitives.Tests.csproj index 235c025a..5210f214 100644 --- a/tests/GraphQL.Primitives.Tests/GraphQL.Primitives.Tests.csproj +++ b/tests/GraphQL.Primitives.Tests/GraphQL.Primitives.Tests.csproj @@ -3,7 +3,7 @@ - net7 + net8 diff --git a/tests/GraphQL.Server.Test/GraphQL.Server.Test.csproj b/tests/GraphQL.Server.Test/GraphQL.Server.Test.csproj index 7220da61..4b81bde3 100644 --- a/tests/GraphQL.Server.Test/GraphQL.Server.Test.csproj +++ b/tests/GraphQL.Server.Test/GraphQL.Server.Test.csproj @@ -1,7 +1,7 @@ - net7 + net8 false diff --git a/tests/IntegrationTestServer/IntegrationTestServer.csproj b/tests/IntegrationTestServer/IntegrationTestServer.csproj index ad1e5255..85b003c9 100644 --- a/tests/IntegrationTestServer/IntegrationTestServer.csproj +++ b/tests/IntegrationTestServer/IntegrationTestServer.csproj @@ -1,7 +1,7 @@  - net7 + net8 IntegrationTestServer.Program false