Skip to content

Commit c4d0fed

Browse files
authored
Merge pull request #31 from Linq2GraphQL/fix-multilevel-select
Fix multilevel select
2 parents ee426c8 + d1ccccb commit c4d0fed

35 files changed

+264
-264
lines changed

src/Linq2GraphQL.Client/QueryNode.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public QueryNode(MemberInfo member, string name = null, List<ArgumentValue> argu
2424
if (!topLevel) {
2525
SetArgumentHashCodeId();
2626
}
27-
2827
}
2928

3029
public bool InterfaceProperty { get; internal set; }

src/Linq2GraphQL.Client/Utilities.cs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Linq2GraphQL.Client;
66

77
public static class Utilities
88
{
9-
109
public static string GetArgumentsId(IEnumerable<object> objects)
1110
{
1211
if (objects == null) return null;
@@ -15,23 +14,26 @@ public static string GetArgumentsId(IEnumerable<object> objects)
1514

1615
unchecked
1716
{
18-
int hash = 19;
17+
var hash = 19;
1918
foreach (var obj in objs)
2019
{
2120
hash = hash * 31 + obj.GetHashCode();
2221
}
23-
var hashString = hash.ToString().Replace("-", "_");
2422

25-
return hashString;
23+
return hash.ToString().Replace("-", "_");
2624
}
2725
}
2826

29-
public static bool IsSelectOrSelectMany(this MethodCallExpression methodCallExpression)
27+
private static bool IsSelectOrSelectMany(this MethodCallExpression methodCallExpression)
3028
{
31-
if (methodCallExpression.Arguments.Count != 2) { return false; };
29+
if (methodCallExpression.Arguments.Count != 2)
30+
{
31+
return false;
32+
}
33+
34+
;
3235
var methodName = methodCallExpression.Method.Name;
3336
return (methodName == "Select" || methodName == "SelectMany");
34-
3537
}
3638

3739
public static void ParseExpression(Expression body, QueryNode parent)
@@ -44,20 +46,18 @@ public static void ParseExpression(Expression body, QueryNode parent)
4446
{
4547
parent.AddChildNode(childNode);
4648
}
47-
4849
}
4950

5051
private static void ParseExpressionInternal(Expression body, QueryNode parent)
5152
{
5253
if (body.NodeType == ExpressionType.MemberInit)
5354
{
5455
var exp = (MemberInitExpression)body;
55-
56-
foreach (MemberAssignment bining in exp.Bindings.Where(e => e.BindingType == MemberBindingType.Assignment).Cast<MemberAssignment>())
56+
foreach (var binding in exp.Bindings.Where(e => e.BindingType == MemberBindingType.Assignment)
57+
.Cast<MemberAssignment>())
5758
{
58-
ParseExpressionInternal(bining.Expression, parent);
59+
ParseExpressionInternal(binding.Expression, parent);
5960
}
60-
6161
}
6262

6363
switch (body)
@@ -72,36 +72,29 @@ private static void ParseExpressionInternal(Expression body, QueryNode parent)
7272
break;
7373

7474
case MethodCallExpression methodCallExp:
75-
7675
ParseMethodCallExpression(parent, methodCallExp);
77-
7876
break;
79-
case NewExpression newExpression:
80-
81-
var t = newExpression;
8277

78+
case NewExpression newExpression:
8379
foreach (var argument in newExpression.Arguments)
8480
{
85-
ParseExpressionInternal(argument, parent);
81+
ParseExpression(argument, parent);
8682
}
87-
break;
88-
89-
9083

84+
break;
9185
}
9286
}
9387

9488
private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpression methodCallExp)
9589
{
96-
var grapInterfaceAttribute = methodCallExp.Method.GetCustomAttribute<GraphInterfaceAttribute>();
97-
if (grapInterfaceAttribute != null)
90+
var graphInterfaceAttribute = methodCallExp.Method.GetCustomAttribute<GraphInterfaceAttribute>();
91+
if (graphInterfaceAttribute != null)
9892
{
9993
var queryNode = new QueryNode(methodCallExp.Method, methodCallExp.Method.Name, null, true);
10094
parent.AddChildNode(queryNode);
10195
return;
10296
}
10397

104-
10598
var graphMethodAttribute = methodCallExp.Method.GetCustomAttribute<GraphMethodAttribute>();
10699
if (graphMethodAttribute != null)
107100
{
@@ -110,8 +103,8 @@ private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpres
110103
var i = 0;
111104
foreach (var parameter in methodCallExp.Method.GetParameters())
112105
{
113-
var graphAtttribute = parameter.GetCustomAttribute<GraphArgumentAttribute>();
114-
if (graphAtttribute != null)
106+
var graphAttribute = parameter.GetCustomAttribute<GraphArgumentAttribute>();
107+
if (graphAttribute != null)
115108
{
116109
var arg = methodCallExp.Arguments[i];
117110
ConstantExpression argConstant;
@@ -125,7 +118,7 @@ private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpres
125118
argConstant = (ConstantExpression)arg;
126119
}
127120

128-
arguments.Add(new ArgumentValue(parameter.Name, graphAtttribute.GraphType,
121+
arguments.Add(new ArgumentValue(parameter.Name, graphAttribute.GraphType,
129122
argConstant.Value));
130123
}
131124

@@ -134,7 +127,6 @@ private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpres
134127

135128
var queryNode = new QueryNode(methodCallExp.Method, graphMethodAttribute.GraphName, arguments);
136129
parent.AddChildNode(queryNode);
137-
138130
}
139131
else if (methodCallExp.IsSelectOrSelectMany())
140132
{
@@ -151,7 +143,7 @@ private static void ParseMethodCallExpression(QueryNode parent, MethodCallExpres
151143
}
152144
}
153145

154-
public static (QueryNode ParentNode, QueryNode LastNode) GetMemberQueryNode(Expression expression)
146+
private static (QueryNode ParentNode, QueryNode LastNode) GetMemberQueryNode(Expression expression)
155147
{
156148
var members = GetMembers(expression);
157149
if (members == null) return (null, null);
@@ -164,7 +156,6 @@ public static (QueryNode ParentNode, QueryNode LastNode) GetMemberQueryNode(Expr
164156
foreach (var member in members)
165157
{
166158
var newNode = new QueryNode(member);
167-
168159
if (parentNode == null)
169160
{
170161
parentNode = newNode;
@@ -181,7 +172,7 @@ public static (QueryNode ParentNode, QueryNode LastNode) GetMemberQueryNode(Expr
181172
}
182173

183174

184-
public static List<MemberInfo> GetMembers(Expression expression)
175+
private static List<MemberInfo> GetMembers(Expression expression)
185176
{
186177
var members = new List<MemberInfo>();
187178
if (expression.NodeType == ExpressionType.MemberAccess)

test/Linq2GraphQL.TestClient/Generated/Inputs/CustomerFilterInput.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ public ListFilterInputTypeOfOrderFilterInput Orders
5050
set => SetValue("orders", value);
5151
}
5252

53+
[JsonPropertyName("address")]
54+
public AddressFilterInput Address
55+
{
56+
get => GetValue<AddressFilterInput>("address");
57+
set => SetValue("address", value);
58+
}
59+
5360
}

test/Linq2GraphQL.TestClient/Generated/Inputs/CustomerInput.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ public List<OrderInput> Orders
3636
set => SetValue("orders", value);
3737
}
3838

39+
[JsonPropertyName("address")]
40+
public AddressInput Address
41+
{
42+
get => GetValue<AddressInput>("address");
43+
set => SetValue("address", value);
44+
}
45+
3946
}

test/Linq2GraphQL.TestClient/Generated/Inputs/CustomerSortInput.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ public SortEnumType? Status
2929
set => SetValue("status", value);
3030
}
3131

32+
[JsonPropertyName("address")]
33+
public AddressSortInput Address
34+
{
35+
get => GetValue<AddressSortInput>("address");
36+
set => SetValue("address", value);
37+
}
38+
3239
}

test/Linq2GraphQL.TestClient/Generated/Inputs/InputFactory.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ public static CustomerFilterInput Orders(this CustomerFilterInput input, Action<
262262
return input;
263263
}
264264

265+
public static CustomerFilterInput Address(this CustomerFilterInput input, Action<AddressFilterInput> mod)
266+
{
267+
var filter = new AddressFilterInput();
268+
mod ??= _ => { };
269+
mod(filter);
270+
input.Address = filter;
271+
return input;
272+
}
273+
265274
}
266275

267276
public static class CustomerInputExtensions
@@ -296,6 +305,15 @@ public static CustomerInput Orders(this CustomerInput input, Action<List<OrderIn
296305
return input;
297306
}
298307

308+
public static CustomerInput Address(this CustomerInput input, Action<AddressInput> mod)
309+
{
310+
var filter = new AddressInput();
311+
mod ??= _ => { };
312+
mod(filter);
313+
input.Address = filter;
314+
return input;
315+
}
316+
299317
}
300318

301319
public static class CustomerSortInputExtensions
@@ -321,6 +339,15 @@ public static CustomerSortInput Status(this CustomerSortInput input, SortEnumTyp
321339
return input;
322340
}
323341

342+
public static CustomerSortInput Address(this CustomerSortInput input, Action<AddressSortInput> mod)
343+
{
344+
var filter = new AddressSortInput();
345+
mod ??= _ => { };
346+
mod(filter);
347+
input.Address = filter;
348+
return input;
349+
}
350+
324351
}
325352

326353
public static class CustomerStatusOperationFilterInputExtensions

test/Linq2GraphQL.TestClient/Generated/Types/Address.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ public partial class Address : GraphQLTypeBase
1111
[JsonPropertyName("name")]
1212
public string Name { get; set; }
1313

14-
1514
[JsonPropertyName("street")]
1615
public string Street { get; set; }
1716

18-
1917
[JsonPropertyName("postalCode")]
2018
public string PostalCode { get; set; }
2119

22-
23-
24-
25-
26-
2720
}

test/Linq2GraphQL.TestClient/Generated/Types/AnimalsConnection.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@ public partial class AnimalsConnection : GraphQLTypeBase, Linq2GraphQL.Client.Co
1111
[JsonPropertyName("pageInfo")]
1212
public Linq2GraphQL.Client.Common.PageInfo PageInfo { get; set; }
1313

14-
1514
[JsonPropertyName("edges")]
1615
public List<AnimalsEdge> Edges { get; set; }
1716

18-
1917
[JsonPropertyName("nodes")]
2018
public List<IAnimal> Nodes { get; set; }
2119

22-
2320
[JsonPropertyName("totalCount")]
2421
public int TotalCount { get; set; }
2522

26-
27-
28-
29-
30-
3123
}

test/Linq2GraphQL.TestClient/Generated/Types/AnimalsEdge.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ public partial class AnimalsEdge : GraphQLTypeBase
1111
[JsonPropertyName("cursor")]
1212
public string Cursor { get; set; }
1313

14-
1514
[JsonPropertyName("node")]
1615
public IAnimal Node { get; set; }
1716

18-
19-
20-
21-
22-
2317
}

test/Linq2GraphQL.TestClient/Generated/Types/CollectionSegmentInfo.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ public partial class CollectionSegmentInfo : GraphQLTypeBase
1111
[JsonPropertyName("hasNextPage")]
1212
public bool HasNextPage { get; set; }
1313

14-
1514
[JsonPropertyName("hasPreviousPage")]
1615
public bool HasPreviousPage { get; set; }
1716

18-
19-
20-
21-
22-
2317
}

0 commit comments

Comments
 (0)