Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Feb 5, 2022
1 parent 64aba34 commit df38551
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 12 additions & 7 deletions tests/Transports.AspNetCore.Tests/NewtonsoftJsonTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -45,10 +46,10 @@ public async Task Decodes_BigInteger()
}

[Fact]
public async Task Dates_Should_Parse_As_Text()
public async Task Dates_Should_Parse_As_Dates()
{
var ret = await Deserialize(@"{""variables"":{""date"":""2015-12-22T10:10:10+03:00""}}");
ret.Single().Variables["date"].ShouldBeOfType<string>().ShouldBe("2015-12-22T10:10:10+03:00");
ret.Single().Variables["date"].ShouldBeOfType<DateTime>().ShouldBe(new DateTimeOffset(2015, 12, 22, 10, 10, 10, TimeSpan.FromHours(3)).LocalDateTime);

This comment has been minimized.

Copy link
@sungam3r

sungam3r Feb 5, 2022

Member

Ooops. That is what I was talking about hall of shame. I'm not sure if it affects us badly now but it can. See JamesNK/Newtonsoft.Json#862 . Imagine variable of StringGraphType and json for that variable:

{
  "mystringvar": "2015-12-22T10:10:10+03:00"
}

NewtonsoftJson will deserialize this variable into DateTime 🤦‍♂️ . And then in StringGraphType.ParseValue:

 public override object? ParseValue(object? value) => value switch
        {
            string _ => value,
            null => null,
            _ => ThrowValueConversionError(value)     <----------- BOOM
        };

So maybe I was too fast suggesting remove serializer settings.

}

[Fact]
Expand All @@ -58,6 +59,14 @@ public async Task Extensions_Null_When_Not_Provided()
ret.Single().Extensions.ShouldBeNull();
}

[Fact]
public async Task Name_Matching_Is_Case_Sensitive()
{
var exception = await Should.ThrowAsync<Newtonsoft.Json.JsonException>(()
=> Deserialize(@"{""VARIABLES"":{""date"":""2015-12-22T10:10:10+03:00""}}"));
exception.Message.ShouldBe("Exception of type 'Newtonsoft.Json.JsonException' was thrown.");
}

[Fact]
public async Task Decodes_Multiple_Queries()
{
Expand Down Expand Up @@ -86,11 +95,7 @@ public async Task Decodes_Nested_Arrays()
private async Task<GraphQLRequest[]> Deserialize(string jsonText)
{
var jsonStream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(jsonText));
var deserializer = new NewtonsoftJson.GraphQLSerializer(config =>
{
config.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
config.DateParseHandling = Newtonsoft.Json.DateParseHandling.None;
});
var deserializer = new NewtonsoftJson.GraphQLSerializer();
return await deserializer.ReadAsync<GraphQLRequest[]>(jsonStream);
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Transports.AspNetCore.Tests/SystemTextJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public async Task Extensions_Null_When_Not_Provided()
[Fact]
public async Task Name_Matching_Is_Case_Sensitive()
{
await Should.ThrowAsync<System.Text.Json.JsonException>(()
var exception = await Should.ThrowAsync<System.Text.Json.JsonException>(()
=> Deserialize(@"{""VARIABLES"":{""date"":""2015-12-22T10:10:10+03:00""}}"));
exception.Message.ShouldBe("The JSON value could not be converted to GraphQL.Transport.GraphQLRequest. Path: $ | LineNumber: 0 | BytePositionInLine: 14. Path: $ | LineNumber: 0 | BytePositionInLine: 1.");
}

[Fact]
Expand Down

0 comments on commit df38551

Please sign in to comment.