Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions src/validation/rules/OverlappingFieldsCanBeMergedRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import type { ObjMap } from '../../jsutils/ObjMap';
import { GraphQLError } from '../../error/GraphQLError';

import type {
ArgumentNode,
FieldNode,
FragmentDefinitionNode,
ObjectValueNode,
SelectionSetNode,
ValueNode,
} from '../../language/ast';
import { Kind } from '../../language/kinds';
import { print } from '../../language/printer';
Expand Down Expand Up @@ -588,12 +587,8 @@ function findConflict(
];
}

// FIXME https://github.com/graphql/graphql-js/issues/2203
const args1 = /* c8 ignore next */ node1.arguments ?? [];
const args2 = /* c8 ignore next */ node2.arguments ?? [];

// Two field calls must have the same arguments.
if (!sameArguments(args1, args2)) {
if (stringifyArguments(node1) !== stringifyArguments(node2)) {
return [
[responseName, 'they have differing arguments'],
[node1],
Expand Down Expand Up @@ -639,26 +634,19 @@ function findConflict(
}
}

function sameArguments(
arguments1: ReadonlyArray<ArgumentNode>,
arguments2: ReadonlyArray<ArgumentNode>,
): boolean {
if (arguments1.length !== arguments2.length) {
return false;
}
return arguments1.every((argument1) => {
const argument2 = arguments2.find(
(argument) => argument.name.value === argument1.name.value,
);
if (!argument2) {
return false;
}
return stringifyValue(argument1.value) === stringifyValue(argument2.value);
});
}

function stringifyValue(value: ValueNode): string {
return print(sortValueNode(value));
function stringifyArguments(fieldNode: FieldNode): string {
// FIXME https://github.com/graphql/graphql-js/issues/2203
const args = /* c8 ignore next */ fieldNode.arguments ?? [];

const inputObjectWithArgs: ObjectValueNode = {
kind: Kind.OBJECT,
fields: args.map((argNode) => ({
kind: Kind.OBJECT_FIELD,
name: argNode.name,
value: argNode.value,
})),
};
return print(sortValueNode(inputObjectWithArgs));
}

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