Skip to content

Commit 5caff03

Browse files
OverlappingFieldsCanBeMergedRule: simplify argument comparison (#3457)
1 parent 730d5af commit 5caff03

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

src/validation/rules/OverlappingFieldsCanBeMergedRule.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import type { ObjMap } from '../../jsutils/ObjMap';
55
import { GraphQLError } from '../../error/GraphQLError';
66

77
import type {
8-
ArgumentNode,
98
FieldNode,
109
FragmentDefinitionNode,
10+
ObjectValueNode,
1111
SelectionSetNode,
12-
ValueNode,
1312
} from '../../language/ast';
1413
import { Kind } from '../../language/kinds';
1514
import { print } from '../../language/printer';
@@ -588,12 +587,8 @@ function findConflict(
588587
];
589588
}
590589

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-
595590
// Two field calls must have the same arguments.
596-
if (!sameArguments(args1, args2)) {
591+
if (stringifyArguments(node1) !== stringifyArguments(node2)) {
597592
return [
598593
[responseName, 'they have differing arguments'],
599594
[node1],
@@ -639,26 +634,19 @@ function findConflict(
639634
}
640635
}
641636

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));
637+
function stringifyArguments(fieldNode: FieldNode): string {
638+
// FIXME https://github.com/graphql/graphql-js/issues/2203
639+
const args = /* c8 ignore next */ fieldNode.arguments ?? [];
640+
641+
const inputObjectWithArgs: ObjectValueNode = {
642+
kind: Kind.OBJECT,
643+
fields: args.map((argNode) => ({
644+
kind: Kind.OBJECT_FIELD,
645+
name: argNode.name,
646+
value: argNode.value,
647+
})),
648+
};
649+
return print(sortValueNode(inputObjectWithArgs));
662650
}
663651

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

0 commit comments

Comments
 (0)