11namespace HotChocolate . Language ;
22
3- internal sealed class SyntaxEqualityComparer : IEqualityComparer < ISyntaxNode >
3+ internal sealed class SyntaxEqualityComparer ( bool ignoreDescriptions = false ) : IEqualityComparer < ISyntaxNode >
44{
55 public bool Equals ( ISyntaxNode ? x , ISyntaxNode ? y )
66 {
@@ -171,7 +171,7 @@ private bool Equals(BooleanValueNode x, BooleanValueNode y)
171171
172172 private bool Equals ( DirectiveDefinitionNode x , DirectiveDefinitionNode y )
173173 => Equals ( x . Name , y . Name )
174- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
174+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
175175 && x . IsRepeatable . Equals ( y . IsRepeatable )
176176 && Equals ( x . Arguments , y . Arguments )
177177 && Equals ( x . Locations , y . Locations ) ;
@@ -184,7 +184,7 @@ private bool Equals(DocumentNode x, DocumentNode y)
184184
185185 private bool Equals ( EnumTypeDefinitionNode x , EnumTypeDefinitionNode y )
186186 => Equals ( x . Name , y . Name )
187- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
187+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
188188 && Equals ( x . Directives , y . Directives )
189189 && Equals ( x . Values , y . Values ) ;
190190
@@ -195,14 +195,14 @@ private bool Equals(EnumTypeExtensionNode x, EnumTypeExtensionNode y)
195195
196196 private bool Equals ( EnumValueDefinitionNode x , EnumValueDefinitionNode y )
197197 => Equals ( x . Name , y . Name )
198- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) ;
198+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) ) ;
199199
200200 private bool Equals ( EnumValueNode x , EnumValueNode y )
201201 => x . AsSpan ( ) . SequenceEqual ( y . AsSpan ( ) ) ;
202202
203203 private bool Equals ( FieldDefinitionNode x , FieldDefinitionNode y )
204204 => Equals ( x . Name , y . Name )
205- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
205+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
206206 && Equals ( x . Directives , y . Directives )
207207 && Equals ( x . Arguments , y . Arguments )
208208 && Equals ( x . Type , y . Type ) ;
@@ -235,7 +235,7 @@ private bool Equals(InlineFragmentNode x, InlineFragmentNode y)
235235
236236 private bool Equals ( InputObjectTypeDefinitionNode x , InputObjectTypeDefinitionNode y )
237237 => Equals ( x . Name , y . Name )
238- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
238+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
239239 && Equals ( x . Directives , y . Directives )
240240 && Equals ( x . Fields , y . Fields ) ;
241241
@@ -246,14 +246,14 @@ private bool Equals(InputObjectTypeExtensionNode x, InputObjectTypeExtensionNode
246246
247247 private bool Equals ( InputValueDefinitionNode x , InputValueDefinitionNode y )
248248 => Equals ( x . Name , y . Name )
249- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
249+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
250250 && Equals ( x . Type , y . Type )
251251 && Equals ( x . DefaultValue , y . DefaultValue )
252252 && Equals ( x . Directives , y . Directives ) ;
253253
254254 private bool Equals ( InterfaceTypeDefinitionNode x , InterfaceTypeDefinitionNode y )
255255 => Equals ( x . Name , y . Name )
256- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
256+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
257257 && Equals ( x . Directives , y . Directives )
258258 && Equals ( x . Interfaces , y . Interfaces )
259259 && Equals ( x . Fields , y . Fields ) ;
@@ -308,7 +308,7 @@ private bool Equals(ObjectFieldNode x, ObjectFieldNode y)
308308
309309 private bool Equals ( ObjectTypeDefinitionNode x , ObjectTypeDefinitionNode y )
310310 => Equals ( x . Name , y . Name )
311- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
311+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
312312 && Equals ( x . Directives , y . Directives )
313313 && Equals ( x . Interfaces , y . Interfaces )
314314 && Equals ( x . Fields , y . Fields ) ;
@@ -335,7 +335,7 @@ private bool Equals(OperationTypeDefinitionNode x, OperationTypeDefinitionNode y
335335
336336 private bool Equals ( ScalarTypeDefinitionNode x , ScalarTypeDefinitionNode y )
337337 => Equals ( x . Name , y . Name )
338- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
338+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
339339 && Equals ( x . Directives , y . Directives ) ;
340340
341341 private bool Equals ( ScalarTypeExtensionNode x , ScalarTypeExtensionNode y )
@@ -349,7 +349,7 @@ private bool Equals(SchemaCoordinateNode x, SchemaCoordinateNode y)
349349 && SyntaxComparer . BySyntax . Equals ( x . ArgumentName , y . ArgumentName ) ;
350350
351351 private bool Equals ( SchemaDefinitionNode x , SchemaDefinitionNode y )
352- => SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
352+ => ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
353353 && Equals ( x . Directives , y . Directives )
354354 && Equals ( x . OperationTypes , y . OperationTypes ) ;
355355
@@ -365,7 +365,7 @@ private bool Equals(StringValueNode x, StringValueNode y)
365365
366366 private bool Equals ( UnionTypeDefinitionNode x , UnionTypeDefinitionNode y )
367367 => Equals ( x . Name , y . Name )
368- && SyntaxComparer . BySyntax . Equals ( x . Description , y . Description )
368+ && ( ignoreDescriptions || SyntaxComparer . BySyntax . Equals ( x . Description , y . Description ) )
369369 && Equals ( x . Directives , y . Directives )
370370 && Equals ( x . Types , y . Types ) ;
371371
@@ -545,7 +545,10 @@ private int GetHashCode(DirectiveDefinitionNode node)
545545 var hashCode = new HashCode ( ) ;
546546 hashCode . Add ( node . Kind ) ;
547547 hashCode . Add ( GetHashCode ( node . Name ) ) ;
548- hashCode . Add ( GetHashCode ( node . Description ) ) ;
548+ if ( ! ignoreDescriptions )
549+ {
550+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
551+ }
549552 hashCode . Add ( node . IsRepeatable ) ;
550553
551554 for ( var i = 0 ; i < node . Arguments . Count ; i ++ )
@@ -597,7 +600,10 @@ private int GetHashCode(EnumTypeDefinitionNode node)
597600 var hashCode = new HashCode ( ) ;
598601 hashCode . Add ( node . Kind ) ;
599602 hashCode . Add ( GetHashCode ( node . Name ) ) ;
600- hashCode . Add ( GetHashCode ( node . Description ) ) ;
603+ if ( ! ignoreDescriptions )
604+ {
605+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
606+ }
601607
602608 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
603609 {
@@ -636,7 +642,9 @@ private int GetHashCode(EnumTypeExtensionNode node)
636642 }
637643
638644 private int GetHashCode ( EnumValueDefinitionNode node )
639- => HashCode . Combine ( node . Kind , GetHashCode ( node . Name ) , GetHashCode ( node . Description ) ) ;
645+ => ignoreDescriptions
646+ ? HashCode . Combine ( node . Kind , GetHashCode ( node . Name ) )
647+ : HashCode . Combine ( node . Kind , GetHashCode ( node . Name ) , GetHashCode ( node . Description ) ) ;
640648
641649 private int GetHashCode ( EnumValueNode node )
642650 => HashCode . Combine ( node . Kind , node . Value ) ;
@@ -646,7 +654,10 @@ private int GetHashCode(FieldDefinitionNode node)
646654 var hashCode = new HashCode ( ) ;
647655 hashCode . Add ( node . Kind ) ;
648656 hashCode . Add ( GetHashCode ( node . Name ) ) ;
649- hashCode . Add ( GetHashCode ( node . Description ) ) ;
657+ if ( ! ignoreDescriptions )
658+ {
659+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
660+ }
650661
651662 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
652663 {
@@ -765,7 +776,10 @@ private int GetHashCode(InputObjectTypeDefinitionNode node)
765776 var hashCode = new HashCode ( ) ;
766777 hashCode . Add ( node . Kind ) ;
767778 hashCode . Add ( GetHashCode ( node . Name ) ) ;
768- hashCode . Add ( GetHashCode ( node . Description ) ) ;
779+ if ( ! ignoreDescriptions )
780+ {
781+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
782+ }
769783
770784 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
771785 {
@@ -808,7 +822,10 @@ private int GetHashCode(InputValueDefinitionNode node)
808822 var hashCode = new HashCode ( ) ;
809823 hashCode . Add ( node . Kind ) ;
810824 hashCode . Add ( GetHashCode ( node . Name ) ) ;
811- hashCode . Add ( GetHashCode ( node . Description ) ) ;
825+ if ( ! ignoreDescriptions )
826+ {
827+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
828+ }
812829 hashCode . Add ( GetHashCode ( node . Type ) ) ;
813830 hashCode . Add ( GetHashCode ( node . DefaultValue ) ) ;
814831
@@ -826,7 +843,10 @@ private int GetHashCode(InterfaceTypeDefinitionNode node)
826843 var hashCode = new HashCode ( ) ;
827844 hashCode . Add ( node . Kind ) ;
828845 hashCode . Add ( GetHashCode ( node . Name ) ) ;
829- hashCode . Add ( GetHashCode ( node . Description ) ) ;
846+ if ( ! ignoreDescriptions )
847+ {
848+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
849+ }
830850
831851 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
832852 {
@@ -947,7 +967,10 @@ private int GetHashCode(ObjectTypeDefinitionNode node)
947967 var hashCode = new HashCode ( ) ;
948968 hashCode . Add ( node . Kind ) ;
949969 hashCode . Add ( GetHashCode ( node . Name ) ) ;
950- hashCode . Add ( GetHashCode ( node . Description ) ) ;
970+ if ( ! ignoreDescriptions )
971+ {
972+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
973+ }
951974
952975 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
953976 {
@@ -1043,7 +1066,10 @@ private int GetHashCode(ScalarTypeDefinitionNode node)
10431066 var hashCode = new HashCode ( ) ;
10441067 hashCode . Add ( node . Kind ) ;
10451068 hashCode . Add ( GetHashCode ( node . Name ) ) ;
1046- hashCode . Add ( GetHashCode ( node . Description ) ) ;
1069+ if ( ! ignoreDescriptions )
1070+ {
1071+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
1072+ }
10471073
10481074 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
10491075 {
@@ -1081,7 +1107,10 @@ private int GetHashCode(SchemaDefinitionNode node)
10811107 {
10821108 var hashCode = new HashCode ( ) ;
10831109 hashCode . Add ( node . Kind ) ;
1084- hashCode . Add ( GetHashCode ( node . Description ) ) ;
1110+ if ( ! ignoreDescriptions )
1111+ {
1112+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
1113+ }
10851114
10861115 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
10871116 {
@@ -1158,7 +1187,10 @@ private int GetHashCode(UnionTypeDefinitionNode node)
11581187 var hashCode = new HashCode ( ) ;
11591188 hashCode . Add ( node . Kind ) ;
11601189 hashCode . Add ( GetHashCode ( node . Name ) ) ;
1161- hashCode . Add ( GetHashCode ( node . Description ) ) ;
1190+ if ( ! ignoreDescriptions )
1191+ {
1192+ hashCode . Add ( GetHashCode ( node . Description ) ) ;
1193+ }
11621194
11631195 for ( var i = 0 ; i < node . Directives . Count ; i ++ )
11641196 {
0 commit comments