Skip to content

Commit 76ec924

Browse files
committed
fix #89 and a few small issues found
1 parent ec35fe1 commit 76ec924

10 files changed

Lines changed: 27 additions & 25 deletions

File tree

‎src/Benchmarks/Benchmarks.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PrivateAssets>all</PrivateAssets>
1414
</PackageReference>
1515
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
16-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
16+
<PackageReference Include="System.Text.Json" Version="6.0.0" />
1717
<ProjectReference Include="../EntityGraphQL/EntityGraphQL.csproj" />
1818

1919
<None Update="./DataLoader/moviedata.json" CopyToOutputDirectory="PreserveNewest" />

‎src/Benchmarks/DataLoader/DataLoader.cs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
5-
using Newtonsoft.Json;
64

75
namespace Benchmarks
86
{

‎src/Benchmarks/DataLoader/MovieData.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using Newtonsoft.Json;
3+
using System.Text.Json.Serialization;
44

55
namespace Benchmarks
66
{
@@ -14,14 +14,14 @@ public class MovieData
1414
public class MoveInfo
1515
{
1616
public List<string> Directors { get; set; }
17-
[JsonProperty("release_date")]
17+
[JsonPropertyName("release_date")]
1818
public DateTime ReleaseDate { get; set; }
1919
public float Rating { get; set; }
2020
public List<string> Genres { get; set; }
2121
public string ImageUrl { get; set; }
2222
public string Plot { get; set; }
2323
public int Rank { get; set; }
24-
[JsonProperty("running_time_secs")]
24+
[JsonPropertyName("running_time_secs")]
2525
public int RunningTimeSecs { get; set; }
2626
public List<string> Actors { get; set; }
2727
}

‎src/EntityGraphQL/Compiler/QueryWalkerHelper.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ public static class QueryWalkerHelper
3939
argValue = argType switch
4040
{
4141
_ when argType == typeof(short) || argType == typeof(short?) => short.Parse(argumentValue.Value?.ToString()),
42+
_ when argType == typeof(ushort) || argType == typeof(ushort?) => ushort.Parse(argumentValue.Value?.ToString()),
4243
_ when argType == typeof(int) || argType == typeof(int?) => int.Parse(argumentValue.Value?.ToString()),
44+
_ when argType == typeof(uint) || argType == typeof(uint?) => uint.Parse(argumentValue.Value?.ToString()),
4345
_ when argType == typeof(long) || argType == typeof(long?) => long.Parse(argumentValue.Value?.ToString()),
46+
_ when argType == typeof(ulong) || argType == typeof(ulong?) => ulong.Parse(argumentValue.Value?.ToString()),
47+
_ when argType == typeof(decimal) || argType == typeof(decimal?) => decimal.Parse(argumentValue.Value?.ToString()),
48+
_ when argType == typeof(double) || argType == typeof(double?) => double.Parse(argumentValue.Value?.ToString()),
4449
_ => argValue
4550
};
4651
break;

‎src/EntityGraphQL/Compiler/Util/ExpressionUtil.cs‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,13 @@ public static MemberExpression CheckAndGetMemberExpression<TBaseType, TReturn>(E
5454
return null;
5555

5656
var objType = value.GetType();
57-
if (typeof(Newtonsoft.Json.Linq.JToken).IsAssignableFrom(objType))
58-
{
59-
value = ((Newtonsoft.Json.Linq.JToken)value).ToObject(type);
60-
}
61-
else if (type == typeof(Newtonsoft.Json.Linq.JObject))
62-
{
63-
value = ((Newtonsoft.Json.Linq.JObject)value).ToObject(type);
64-
}
65-
else if (typeof(JsonElement).IsAssignableFrom(objType))
57+
// Default JSON deserializer will deserialize child objects in QueryVariables as this JSON type
58+
if (typeof(JsonElement).IsAssignableFrom(objType))
6659
{
6760
value = ((JsonElement)value).Deserialize(type, new JsonSerializerOptions
6861
{
6962
IncludeFields = true,
70-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
63+
PropertyNameCaseInsensitive = true,
7164
});
7265
}
7366

‎src/EntityGraphQL/EntityGraphQL.csproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<PackageReference Include="Humanizer.Core" Version="2.11.10" />
2323
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
2424
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
25-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2625
<PackageReference Include="System.Text.Json" Version="6.0.0" />
2726
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2827
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />

‎src/EntityGraphQL/QueryRequest.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class QueryRequest
1414
/// </summary>
1515
/// <value></value>
1616
public string? Query { get; set; }
17+
/// <summary>
18+
/// Variables values for the query.
19+
/// It is a Dictionary<string, object?> type. Make sure that object is a resolved .NET type and
20+
/// not a JsonElement/JObject (e.g. turn objects into more dictionaries)
21+
/// </summary>
1722
public QueryVariables? Variables { get; set; }
1823
}
1924

‎src/EntityGraphQL/Schema/MutationType.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private object AssignArgValues(Dictionary<string, Expression> gqlRequestArgs, Fu
125125
object? value = GetValue(gqlRequestArgs, propName, prop.PropertyType);
126126
prop.SetValue(argInstance, value);
127127
foundProp = true;
128+
break;
128129
}
129130
}
130131
if (!foundProp)
@@ -137,6 +138,7 @@ private object AssignArgValues(Dictionary<string, Expression> gqlRequestArgs, Fu
137138
object? value = GetValue(gqlRequestArgs, fieldName, field.FieldType);
138139
field.SetValue(argInstance, value);
139140
foundProp = true;
141+
break;
140142
}
141143
}
142144
}

‎src/tests/EntityGraphQL.Tests/MutationTests/MutationTests.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ id name lastName
108108
}",
109109
// object will come through as json in the request
110110
Variables = new QueryVariables {
111-
{"names", Newtonsoft.Json.JsonConvert.DeserializeObject("{\"name\": \"Lisa\", \"lastName\": \"Simpson\"}")}
112-
}
111+
{ "names", new { name = "Lisa", lastName = "Simpson" } }
112+
}
113113
};
114114
var result = schemaProvider.ExecuteRequest(gql, new TestDataContext(), null, null);
115115
Assert.Null(result.Errors);

‎src/tests/EntityGraphQL.Tests/SortTests/SortTests.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using EntityGraphQL.Schema;
55
using EntityGraphQL.Schema.FieldExtensions;
6-
using Newtonsoft.Json;
6+
using System.Text.Json;
77

88
namespace EntityGraphQL.Tests
99
{
@@ -20,7 +20,7 @@ public void SupportUseSort()
2020
Query = @"query($sort: PersonSortInput) {
2121
people(sort: $sort) { lastName }
2222
}",
23-
Variables = JsonConvert.DeserializeObject<QueryVariables>("{ \"sort\": { \"lastName\": \"DESC\" } }")
23+
Variables = JsonSerializer.Deserialize<QueryVariables>("{ \"sort\": { \"lastName\": \"DESC\" } }")
2424
};
2525
var context = new TestDataContext().FillWithTestData();
2626
context.People.Add(new Person
@@ -44,7 +44,7 @@ public void TestAttribute()
4444
Query = @"query($sort: PersonSortInput) {
4545
people(sort: $sort) { lastName }
4646
}",
47-
Variables = JsonConvert.DeserializeObject<QueryVariables>("{ \"sort\": { \"lastName\": \"DESC\" } }")
47+
Variables = JsonSerializer.Deserialize<QueryVariables>("{ \"sort\": { \"lastName\": \"DESC\" } }")
4848
};
4949
TestDataContext2 context = new();
5050
context.FillWithTestData();
@@ -80,7 +80,7 @@ public void SupportUseSortSelectSortFields()
8080
Query = @"query($sort: PersonSortInput) {
8181
people(sort: $sort) { lastName }
8282
}",
83-
Variables = JsonConvert.DeserializeObject<QueryVariables>("{ \"sort\": { \"height\": \"ASC\" } }")
83+
Variables = JsonSerializer.Deserialize<QueryVariables>("{ \"sort\": { \"height\": \"ASC\" } }")
8484
};
8585
var context = new TestDataContext().FillWithTestData();
8686
context.People.Add(new Person
@@ -178,7 +178,7 @@ public void SupportUseSortOnNonRoot()
178178
tasks(sort: $sort) { id }
179179
}
180180
}",
181-
Variables = JsonConvert.DeserializeObject<QueryVariables>("{ \"sort\": { \"id\": \"DESC\" } }")
181+
Variables = JsonSerializer.Deserialize<QueryVariables>("{ \"sort\": { \"id\": \"DESC\" } }")
182182
};
183183
var context = new TestDataContext().FillWithTestData();
184184
var tree = schema.ExecuteRequest(gql, context, null, null);
@@ -205,7 +205,7 @@ public void SupportUseSortOnNonRoot2()
205205
tasks(sort: $sort) { id }
206206
}
207207
}",
208-
Variables = JsonConvert.DeserializeObject<QueryVariables>("{ \"sort\": { \"id\": \"DESC\" } }")
208+
Variables = JsonSerializer.Deserialize<QueryVariables>("{ \"sort\": { \"id\": \"DESC\" } }")
209209
};
210210
var context = new TestDataContext().FillWithTestData();
211211
var tree = schema.ExecuteRequest(gql, context, null, null);

0 commit comments

Comments
 (0)