Skip to content

Commit 7548ded

Browse files
Fix ObjectValueNode comparison
1 parent fd465ae commit 7548ded

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/HotChocolate/Core/src/Validation/Rules/FieldVisitor.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private static bool AreArgumentsIdentical(FieldNode fieldA, FieldNode fieldB)
370370

371371
if (BySyntax.Equals(argumentA.Name, argumentB.Name))
372372
{
373-
if (BySyntax.Equals(argumentA.Value, argumentB.Value))
373+
if (IsValueIdentical(argumentA.Value, argumentB.Value))
374374
{
375375
validPairs++;
376376
}
@@ -383,6 +383,50 @@ private static bool AreArgumentsIdentical(FieldNode fieldA, FieldNode fieldB)
383383
return fieldA.Arguments.Count == validPairs;
384384
}
385385

386+
private static bool IsValueIdentical(
387+
IValueNode? valueA,
388+
IValueNode? valueB)
389+
{
390+
if (valueA is null && valueB is null)
391+
{
392+
return true;
393+
}
394+
395+
if (valueA is null || valueB is null)
396+
{
397+
return false;
398+
}
399+
400+
if (valueA is ObjectValueNode objectA && valueB is ObjectValueNode objectB)
401+
{
402+
var validPairs = 0;
403+
404+
for (var i = 0; i < objectA.Fields.Count; i++)
405+
{
406+
var fieldA = objectA.Fields[i];
407+
408+
for (var j = 0; j < objectB.Fields.Count; j++)
409+
{
410+
var fieldB = objectB.Fields[j];
411+
412+
if (BySyntax.Equals(fieldA.Name, fieldB.Name))
413+
{
414+
if (IsValueIdentical(fieldA.Value, fieldB.Value))
415+
{
416+
validPairs++;
417+
}
418+
419+
break;
420+
}
421+
}
422+
}
423+
424+
return objectA.Fields.Count == validPairs;
425+
}
426+
427+
return BySyntax.Equals(valueA, valueB);
428+
}
429+
386430
private static bool SameResponseShape(IType typeA, IType typeB)
387431
{
388432
while (!typeA.IsNamedType() && !typeB.IsNamedType())

0 commit comments

Comments
 (0)