Skip to content

Commit 8d4613f

Browse files
committed
fix ReadToken in GraphQLExtensionsConverter for Newtonsoft
1 parent 54cf670 commit 8d4613f

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/GraphQL.Client.Serializer.Newtonsoft/GraphQLExtensionsConverter.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,17 @@ public override GraphQLExtensionsType ReadJson(JsonReader reader, Type objectTyp
2424
}
2525

2626
private object ReadToken(JToken? token) =>
27-
token.Type switch
27+
token switch
2828
{
29-
JTokenType.Undefined => null,
30-
JTokenType.None => null,
31-
JTokenType.Null => null,
32-
JTokenType.Object => ReadDictionary<Dictionary<string, object>>(token),
33-
JTokenType.Array => ReadArray(token),
34-
JTokenType.Integer => token.Value<int>(),
35-
JTokenType.Float => token.Value<double>(),
36-
JTokenType.Raw => token.Value<string>(),
37-
JTokenType.String => token.Value<string>(),
38-
JTokenType.Uri => token.Value<string>(),
39-
JTokenType.Boolean => token.Value<bool>(),
40-
JTokenType.Date => token.Value<DateTime>(),
41-
JTokenType.Bytes => token.Value<byte[]>(),
42-
JTokenType.Guid => token.Value<Guid>(),
43-
JTokenType.TimeSpan => token.Value<TimeSpan>(),
44-
JTokenType.Constructor => throw new ArgumentOutOfRangeException(nameof(token.Type), "cannot deserialize a JSON constructor"),
45-
JTokenType.Property => throw new ArgumentOutOfRangeException(nameof(token.Type), "cannot deserialize a JSON property"),
46-
JTokenType.Comment => throw new ArgumentOutOfRangeException(nameof(token.Type), "cannot deserialize a JSON comment"),
29+
JObject jObject => ReadDictionary<Dictionary<string, object>>(jObject),
30+
JArray jArray => ReadArray(jArray),
31+
JValue jValue => jValue.Value,
32+
JConstructor _ => throw new ArgumentOutOfRangeException(nameof(token.Type),
33+
"cannot deserialize a JSON constructor"),
34+
JProperty _ => throw new ArgumentOutOfRangeException(nameof(token.Type),
35+
"cannot deserialize a JSON property"),
36+
JContainer _ => throw new ArgumentOutOfRangeException(nameof(token.Type),
37+
"cannot deserialize a JSON comment"),
4738
_ => throw new ArgumentOutOfRangeException(nameof(token.Type))
4839
};
4940

@@ -69,6 +60,8 @@ private IEnumerable<object> ReadArray(JToken element)
6960
}
7061
}
7162

63+
private object ReadNumber(JToken token) => ((JValue) token).Value;
64+
7265
private bool IsUnsupportedJTokenType(JTokenType type) => type == JTokenType.Constructor || type == JTokenType.Property || type == JTokenType.Comment;
7366
}
7467
}

tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatQuery.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public class ChatQuery : ObjectGraphType
1010

1111
public static readonly Dictionary<string, object> TestExtensions = new Dictionary<string, object> {
1212
{"extension1", "hello world"},
13-
{"another extension", 4711}
13+
{"another extension", 4711},
14+
{"long", 19942590700}
1415
};
1516

1617
// properties for unit testing

0 commit comments

Comments
 (0)