11using System . Reflection ;
2+ using System . Runtime . CompilerServices ;
23using System . Text . Json . Serialization ;
34using Linq2GraphQL . Client ;
45using Linq2GraphQL . Client . Schema ;
@@ -12,6 +13,27 @@ public class QueryNode
1213
1314 public QueryNode ( MemberInfo member , string name = null , List < ArgumentValue > arguments = null , bool interfaceProperty = false )
1415 {
16+
17+ //https://stackoverflow.com/questions/8094867/good-gethashcode-override-for-list-of-foo-objects-respecting-the-order
18+ var argValues = arguments ? . Where ( e => e . Value != null ) . Select ( e => e . Value ) . ToList ( ) ;
19+ if ( argValues ? . Any ( ) == true )
20+ {
21+ var ll = "" ;
22+ foreach ( var arg in argValues )
23+ {
24+ ll += arg . GetHashCode ( ) . ToString ( ) ;
25+ }
26+ var hashCode = ll . GetHashCode ( ) ;
27+
28+ if ( hashCode < 0 )
29+ {
30+ hashCode = hashCode * - 1 ;
31+ }
32+
33+ ArgumentHashCode = hashCode ;
34+ Alias = "Arg" + hashCode . ToString ( ) ;
35+ }
36+
1537 Name = name ?? member . GetCustomAttribute < JsonPropertyNameAttribute > ( ) ? . Name ?? member . Name . ToCamelCase ( ) ;
1638 Member = member ;
1739 Arguments = arguments ?? new List < ArgumentValue > ( ) ;
@@ -23,6 +45,8 @@ public QueryNode(MemberInfo member, string name = null, List<ArgumentValue> argu
2345
2446 public bool InterfaceProperty { get ; internal set ; }
2547 public string Name { get ; internal set ; }
48+ public string Alias { get ; internal set ; }
49+ public int ArgumentHashCode { get ; internal set ; }
2650 public MemberInfo Member { get ; internal set ; }
2751 public List < QueryNode > ChildNodes { get ; internal set ; } = new ( ) ;
2852 public List < ArgumentValue > Arguments { get ; internal set ; } = new ( ) ;
@@ -67,7 +91,14 @@ public void AddChildNode(MemberInfo member, string name = null)
6791
6892 public void AddChildNode ( QueryNode childNode )
6993 {
70- var currentNode = ChildNodes . FirstOrDefault ( e => e . Name == childNode . Name ) ;
94+
95+ if ( childNode . ArgumentHashCode != 0 )
96+ {
97+ var tt = "ss" ;
98+ }
99+
100+
101+ var currentNode = ChildNodes . FirstOrDefault ( e => e . Name == childNode . Name && e . ArgumentHashCode == childNode . ArgumentHashCode ) ;
71102 if ( currentNode == null )
72103 {
73104 childNode . Parent = this ;
@@ -203,6 +234,10 @@ internal string GetQueryString(string indent = "")
203234 query = "... on " + Name + GetArgumentString ( ) + Environment . NewLine ;
204235
205236 }
237+ else if ( ! string . IsNullOrWhiteSpace ( Alias ) )
238+ {
239+ query = Alias + ":" + Name + GetArgumentString ( ) + Environment . NewLine ;
240+ }
206241 else
207242 {
208243 query = Name + GetArgumentString ( ) + Environment . NewLine ;
0 commit comments