@@ -7,8 +7,8 @@ import type {
77 DirectiveNode ,
88 FieldNode ,
99 FragmentDefinitionNode ,
10- ObjectValueNode ,
1110 SelectionSetNode ,
11+ ValueNode ,
1212} from '../../language/ast.js' ;
1313import { Kind } from '../../language/kinds.js' ;
1414import { print } from '../../language/printer.js' ;
@@ -592,7 +592,7 @@ function findConflict(
592592 }
593593
594594 // Two field calls must have the same arguments.
595- if ( stringifyArguments ( node1 ) !== stringifyArguments ( node2 ) ) {
595+ if ( ! sameArguments ( node1 , node2 ) ) {
596596 return [
597597 [ responseName , 'they have differing arguments' ] ,
598598 [ node1 ] ,
@@ -649,19 +649,38 @@ function findConflict(
649649 }
650650}
651651
652- function stringifyArguments ( fieldNode : FieldNode | DirectiveNode ) : string {
653- // FIXME https://github.com/graphql/graphql-js/issues/2203
654- const args = /* c8 ignore next */ fieldNode . arguments ?? [ ] ;
655-
656- const inputObjectWithArgs : ObjectValueNode = {
657- kind : Kind . OBJECT ,
658- fields : args . map ( ( argNode ) => ( {
659- kind : Kind . OBJECT_FIELD ,
660- name : argNode . name ,
661- value : argNode . value ,
662- } ) ) ,
663- } ;
664- return print ( sortValueNode ( inputObjectWithArgs ) ) ;
652+ function sameArguments (
653+ node1 : FieldNode | DirectiveNode ,
654+ node2 : FieldNode | DirectiveNode ,
655+ ) : boolean {
656+ const args1 = node1 . arguments ;
657+ const args2 = node2 . arguments ;
658+
659+ if ( args1 === undefined || args1 . length === 0 ) {
660+ return args2 === undefined || args2 . length === 0 ;
661+ }
662+ if ( args2 === undefined || args2 . length === 0 ) {
663+ return false ;
664+ }
665+
666+ if ( args1 . length !== args2 . length ) {
667+ return false ;
668+ }
669+
670+ const values2 = new Map ( args2 . map ( ( { name, value } ) => [ name . value , value ] ) ) ;
671+ return args1 . every ( ( arg1 ) => {
672+ const value1 = arg1 . value ;
673+ const value2 = values2 . get ( arg1 . name . value ) ;
674+ if ( value2 === undefined ) {
675+ return false ;
676+ }
677+
678+ return stringifyValue ( value1 ) === stringifyValue ( value2 ) ;
679+ } ) ;
680+ }
681+
682+ function stringifyValue ( value : ValueNode ) : string | null {
683+ return print ( sortValueNode ( value ) ) ;
665684}
666685
667686function getStreamDirective (
@@ -681,7 +700,7 @@ function sameStreams(
681700 return true ;
682701 } else if ( stream1 && stream2 ) {
683702 // check if both fields have equivalent streams
684- return stringifyArguments ( stream1 ) === stringifyArguments ( stream2 ) ;
703+ return sameArguments ( stream1 , stream2 ) ;
685704 }
686705 // fields have a mix of stream and no stream
687706 return false ;
0 commit comments