Skip to content

Commit d1037a5

Browse files
committed
OverlappingFieldsCanBeMergedRule: simplify argument comparison
1 parent 40c160e commit d1037a5

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/validation/rules/OverlappingFieldsCanBeMergedRule.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,8 @@ function findConflict(
588588
];
589589
}
590590

591-
// FIXME https://github.com/graphql/graphql-js/issues/2203
592-
const args1 = /* c8 ignore next */ node1.arguments ?? [];
593-
const args2 = /* c8 ignore next */ node2.arguments ?? [];
594-
595591
// Two field calls must have the same arguments.
596-
if (!sameArguments(args1, args2)) {
592+
if (stringifyArguments(node1) !== stringifyArguments(node2)) {
597593
return [
598594
[responseName, 'they have differing arguments'],
599595
[node1],
@@ -639,26 +635,19 @@ function findConflict(
639635
}
640636
}
641637

642-
function sameArguments(
643-
arguments1: ReadonlyArray<ArgumentNode>,
644-
arguments2: ReadonlyArray<ArgumentNode>,
645-
): boolean {
646-
if (arguments1.length !== arguments2.length) {
647-
return false;
648-
}
649-
return arguments1.every((argument1) => {
650-
const argument2 = arguments2.find(
651-
(argument) => argument.name.value === argument1.name.value,
652-
);
653-
if (!argument2) {
654-
return false;
655-
}
656-
return stringifyValue(argument1.value) === stringifyValue(argument2.value);
657-
});
658-
}
659-
660-
function stringifyValue(value: ValueNode): string {
661-
return print(sortValueNode(value));
638+
function stringifyArguments(fieldNode: FieldNode): string {
639+
// FIXME https://github.com/graphql/graphql-js/issues/2203
640+
const args = /* c8 ignore next */ fieldNode.arguments ?? [];
641+
642+
const inputObjectWithArgs = {
643+
kind: Kind.OBJECT,
644+
fields: args.map((argNode) => ({
645+
kind: Kind.OBJECT_FIELD,
646+
name: argNode.name,
647+
value: argNode.value,
648+
})),
649+
};
650+
return print(sortValueNode(inputObjectWithArgs));
662651
}
663652

664653
// Two types conflict if both types could not apply to a value simultaneously.

0 commit comments

Comments
 (0)